Created
March 7, 2012 00:28
-
-
Save rodriamaro/1990087 to your computer and use it in GitHub Desktop.
Executing a HTTP POST Request with HttpClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void postData() { | |
// Create a new HttpClient and Post Header | |
HttpClient httpclient = new DefaultHttpClient(); | |
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php"); | |
try { | |
// Add your data | |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); | |
nameValuePairs.add(new BasicNameValuePair("id", "12345")); | |
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); | |
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment