HttpPost将数据从Android发送到http - 空白页面

时间:2013-04-22 22:12:15

标签: java android http-post

我准备了一个应用程序,它必须将数据发送到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 $_POSTecho,但我仍然会看到空白页。

0 个答案:

没有答案