Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Android API has a set of functions that allows you to use HTTP requests, POST, GET etc. In this example i will provide a set of code that will allow you to update the contents of a file in a server using POST requests.</p> <p>Our server side code will be very simple and it will be written in PHP. The code will get data from a post request, update a file with the data and load this file to display it in a browser.</p> <p>Create PHP page on server "mypage.php", the code for php page is:-</p> <pre><code> &lt;?php $filename="datatest.html"; file_put_contents($filename,$_POST["fname"]."&lt;br /&gt;",FILE_APPEND); file_put_contents($filename,$_POST["fphone"]."&lt;br /&gt;",FILE_APPEND); file_put_contents($filename,$_POST["femail"]."&lt;br /&gt;",FILE_APPEND); file_put_contents($filename,$_POST["fcomment"]."&lt;br /&gt;",FILE_APPEND); $msg=file_get_contents($filename); echo $msg; ?&gt; </code></pre> <p>Create Android Project and write below code in HTTPExample.java</p> <pre><code> HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://example.com/mypage.php"); try { List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(4); nameValuePairs.add(new BasicNameValuePair("fname", "vinod")); nameValuePairs.add(new BasicNameValuePair("fphone", "1234567890")); nameValuePairs.add(new BasicNameValuePair("femail", "abc@gmail.com")); nameValuePairs.add(new BasicNameValuePair("fcomment", "Help")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httpclient.execute(httppost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } </code></pre> <p>Add permission in AndroidManifest.xml</p> <pre><code> &lt;uses-permission android:name="android.permission.INTERNET"/&gt; </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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