Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I see/use the data sent by a http POST?
    primarykey
    data
    text
    <p>I have been searching through SO for the last few days and have found many Q/A regarding my problem but have not been about to solve it. I am trying to make an Android app that sends 4 (maybe 5) pieces of data to a php script on my webserver. I believe this code does that:</p> <pre><code> HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.mydomain.com/myscript.php"); try { // Add your data List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(4); nameValuePairs.add(new BasicNameValuePair("name", "name")); nameValuePairs.add(new BasicNameValuePair("var1", "var1")); nameValuePairs.add(new BasicNameValuePair("var2", "var2")); nameValuePairs.add(new BasicNameValuePair("var3", "var3")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } </code></pre> <p>My question is this: Hows does this data get sent? I thought it would be in this format <a href="http://www.mydomain.com/myscript.php?name=name&amp;var1=var1&amp;var2=var2&amp;var3=var3" rel="nofollow">http://www.mydomain.com/myscript.php?name=name&amp;var1=var1&amp;var2=var2&amp;var3=var3</a></p> <p>So I thought this myscript.php would work:</p> <pre><code> &lt;?php $name = $_GET['name']; $filename = "newfile.php"; $newfile = fopen($filename, 'w+'); fwrite($newfile, $name); fclose($newfile); ?&gt; </code></pre> <p>I have tried a lot of various ways, like $name = file_get_contents('php://input') to try and see what is being received but no luck.</p> <p>I am new to android and php so I presume I am missing something quite obvious, since all the other Q/A on SO seem to skip the 'how to retrieve and use the data being sent'. All I need the php script to do is grab the 4 variables and write a new file as above with them in it.</p> <p>I would also like to know how to get a response back to the app simply saying the data has been received. I presume that is handled by the variable 'response' but am not able to test that yet. </p> <p>Can someone point me in the right direction? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload