【发布时间】:2012-05-02 19:08:50
【问题描述】:
我是 java / android 新手,因为我为 IOS 安排了时间,但我怀疑是否将参数发送到 PHP 中的函数
嗯,是一个表单,当用户点击发送时,我将表单的内容保存在字符串中。
最后有 4 个字符串
名称 电子邮件 名称用户 邮箱用户
我需要将它们发送到 php 中运行,我遵循了这个tutorial:
但我的问题是将字符串的值作为函数的参数
在 IOS 中做了以下操作:
....
NSString *urlEnvio = [[NSString alloc] initWithFormat:@"http://www.xxxx.com.br/indicar.php?destinatario=%@&remetente=%@&nomedestinatario=%@&nome=%@&enviar=%@", destinatario, remetente, nome,nomeRemetente, check];
...
是我需要java的东西。
根据要求,我编辑了帖子 .....
@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();
}
....
用参数发送到这个地址:姓名、电子邮件、strNomeAmigo、strEmailAmigo
类似这样的:http://www.xxxxx.com.br/indicar.php?nome=name_example&email=example@example.com......
【问题讨论】:
-
这个问题完全不可读,并且没有任何迹象表明您还尝试过任何事情。
-
我确实做了教程的链接,唯一的区别是我想将字符串作为参数发送到我的 PHP 函数。
-
我非常同意 Flamarri 的观点,但如果你能更好地解释自己,我很乐意提供帮助。我一直在进行 android-php 通信。你想使用 json 还是纯文本, GET 或 POST ,你试过没有成功吗?如果你这样做了,那么你尝试了什么?
-
我编辑了帖子,看看