Question

public void postData() {  
        // Create a new HttpClient and Post Header  
        HttpClient httpclient = new DefaultHttpClient();  
        HttpPost httppost = new HttpPost("http://localhost/howdy/welcome.php");  

        try {  

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
            nameValuePairs.add(new BasicNameValuePair("name", "rxn"));  
            nameValuePairs.add(new BasicNameValuePair("id", "b15803"));  
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  

            // Execute HTTP Post Request  
            HttpResponse response = httpclient.execute(httppost);  
            int status = response.getStatusLine().getStatusCode();  
            System.out.println("data posted, status = " + status);  

        } catch (ClientProtocolException e) {  
            // TODO Auto-generated catch block  
        } catch (IOException e) {  
            // TODO Auto-generated catch block  
        } 





    }

Here is my code to post name and id to my local server. now what will be the php code to accept these arguments so that i can able to store in a variable and echo on web page. Thanks in advance

Was it helpful?

Solution

You're sending this data as a POST request, so on the other side simply get it using the $_POST variable. This would be an example:

$name = $_POST['name'];
$id = $_POST['id'];

echo "Hi, my name is $name and my id is $id\n";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top