Skip to content

Instantly share code, notes, and snippets.

@solarsailer
Created April 6, 2011 15:45
Show Gist options
  • Save solarsailer/905886 to your computer and use it in GitHub Desktop.
Save solarsailer/905886 to your computer and use it in GitHub Desktop.
HttpRequest & Client
private HttpClient client;
public HttpModule() {
client = new DefaultHttpClient();
}
public void executePost() {
HttpPost post = new HttpPost(APIConfiguration.getURL(Protocol.HTTPS, "user"));
Console.log(post.getURI());
try {
List<NameValuePair> data = new ArrayList<NameValuePair>();
data.add(new BasicNameValuePair("version", APIConfiguration.API_VERSION));
data.add(new BasicNameValuePair("mail", "bidon@truc.com"));
post.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = client.execute(post);
Console.log(new BasicResponseHandler().handleResponse(response));
} catch (ClientProtocolException e) {
Console.err(e);
} catch (IOException e) {
Console.err(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment