我准备了一个应用程序,它必须将数据发送到http网页,但结果是一个空白区域。 代码如下:
public void onClick(View v) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://web.utk.edu/~nikolo01/locator.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "nikolo01"));
nameValuePairs.add(new BasicNameValuePair("message", "hello"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
HttpResponse response = httpclient.execute(httppost);
String text = EntityUtils.toString(response.getEntity());
Log.i("","response = "+text);
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
}
catch (IOException e) {
// TODO Auto-generated catch block
}
}
});
我在网页上使用PHP $_POST
和echo
,但我仍然会看到空白页。