I got problem with sending data in Android using httpPost. I found some example, and I don’t have any error or exception but on the php site $_POST is always empty/null.
So here is my code:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xxxxxxx.com/test.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("v", "123"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
String responseText = EntityUtils.toString(response.getEntity());
Toast.makeText(this, responseText, 5000).show();
System.out.println(responseText);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
PHP:
<?php
$t=$_POST['v'];
print $t;
?>
and it does not prints 123…
addition:
As you can see there is a String responseText.
In that string i can see that there is the “123” what i wanted to print.
You have typo in the print (you’re missing “_”).
Change print
$POST['v'];to print$_POST['v'];or simplyprint $t;