我有送價值從機器人到PHP和HttpPost 但我得到響應「請求的URL不能被檢索」請求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(新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()));
什麼是'sendValue'設置? – 2011-03-22 12:14:32
您是否在清單文件中設置了網絡權限? – Olegas 2011-03-22 13:45:01
是的,我已設置權限訪問互聯網在清單文件.. – pensilhijau 2011-03-22 15:01:25