I am new to Android programming, but have decent knowledge of PHP.
I am trying to send data to my server via post request. I have the following code:
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year","1980"));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream inps = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inps));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
inps.close();
result=sb.toString();
Log.v("data-received",result);
I have found the code at numerous places all over the Internet.
On the PHP side I am writing this:
<?php
echo "something".$_REQUEST['year'];
?>
But I am only getting "something" (in the Log value "data-received") as the output at my app end?
What am I doing wrong? Do I need to set any environment variable, etc.?