0
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

1 Answer 1

1

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";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.