【发布时间】:2011-03-22 11:56:19
【问题描述】:
我已经使用 HttpPost 从 android 向 PHP 发送值 但我得到响应“无法检索请求 url”
这是我的代码
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(link);
post.setEntity(new UrlEncodedFormEntity(sendValue));
HttpResponse response = client.execute(post);
Toast.makeText(this, response.getStatusLine().toString(),
Toast.LENGTH_LONG).show();
if (response.getStatusLine().toString().contains("200")) {
Toast.makeText(this, "Komentar berhasil dibuat",
Toast.LENGTH_LONG).show();
finish();
}
else{
Toast.makeText(this, "Koneksi server bermasalah",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e("log_tag", "Error connection" + e.toString());
}
但如果我删除“post.setEntity(new UrlEncodedFormEntity(sendValue));” 我可以连接到 PHP 文件..
如何解决?
编辑
我是这样设置的
private List<NameValuePair> sendValue = new ArrayList<NameValuePair>(4);
sendValue.add(new BasicNameValuePair("link", urlShare.toString()));
sendValue.add(new BasicNameValuePair("message", postComment.getText().toString()));
sendValue.add(new BasicNameValuePair("name", nameText.getText().toString()));
sendValue.add(new BasicNameValuePair("email", emailText.getText().toString()));
【问题讨论】:
-
你在清单文件中设置了网络权限吗?
-
是的,我已经在清单文件中设置了访问 INTERNET 的权限..
标签: php android httpclient http-post