2012-02-03 12:31



I am trying to output POST-data that I send from an android phone, however I cannot manage to get any output in my PHP file. This is my php code:

  echo "POSTed data: '".$_POST['mydata']."'<br>";

this is my android code (which seems to work fine)

HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httppost = new HttpPost("myurl.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
nameValuePairs.add(new BasicNameValuePair("mydata", "12345"));  
nameValuePairs.add(new BasicNameValuePair("stringData", "SomeData"));  
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  

// Execute HTTP Post Request  
HttpResponse response = httpclient.execute(httppost);  
String responseText = EntityUtils.toString(response.getEntity()); 

Is it even possible to send POST data to an static PHP script via phone?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douzhi9395 douzhi9395 9年前

    What you have got is working fine - but when you echo something in PHP its echo'd back to the caller - ie the browser in this case.

    If you check the value of response in the code on Android is will be POSTed data: '12344'<br>

    See the error_log() function in PHP for logging to a file

    点赞 评论 复制链接分享