Reputation: 1195
I'm new in java / android, since I schedule for IOS and I'm with a doubt to send parameters to a function in PHP
well, is a form, when the User clicks on send, I save the contents of the form in strings.
have strings 4 at the end
name email nameUser EmailUser
I need to send them to function in php, I followed this tutorial:
but my problem is to have the value of strings as parameter to the function
In the IOS did the following:
....
NSString *urlEnvio = [[NSString alloc] initWithFormat:@"http://www.xxxx.com.br/indicar.php?destinatario=%@&remetente=%@&nomedestinatario=%@&nome=%@&enviar=%@", destinatario, remetente, nome,nomeRemetente, check];
...
is something I need java.
As requested, I edited the post .....
@Override
public void onClick(View v) {
String nome = seuNome.getText().toString();
String email = seuEmail.getText().toString();
String strNomeAmigo = nomeAmigo.getText().toString();
String strEmailAmigo = emailAmigo.getText().toString();
//chama funcao que envia
indicar();
}
});
}
public void indicar(){
new Thread(new Runnable() {
public void run() {
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://www.xxxx.com.br/indicar.php?"));
//send to this address with the parameters: name, email, strNomeAmigo, strEmailAmigo
//
HttpResponse response = client.execute(request);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
System.out.println(page);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}).start();
}
....
send to this address with the parameters: name, email, strNomeAmigo, strEmailAmigo
something like this: http://www.xxxxx.com.br/indicar.php?nome=name_example&[email protected]......
Upvotes: 0
Views: 1462
Reputation: 36302
There are a number of ways to concatenate a string in Java. One way to format a string is with String.format
:
String urlEnvio = String.format("http://www.xxxx.com.br/indicar.php?destinatario=%s&remetente=%s&nomedestinatario=%s&nome=%s&enviar=%s", destinatario, remetente, nome, nomeRemetente, check);
I prefer to use something that validates and properly escapes parameters though, so I prefer Uri.Builder
.
Upvotes: 0
Reputation: 770
Your problem is encoding a url with your parameters, right? If so, you can use String.format for this. This How do I encode URI parameter values? SO question also address the same problem.
Upvotes: 1