Skip to content

Instantly share code, notes, and snippets.

@hujj0615
Created December 4, 2012 07:30
Show Gist options
  • Save hujj0615/4201554 to your computer and use it in GitHub Desktop.
Save hujj0615/4201554 to your computer and use it in GitHub Desktop.
httpclient post example
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://localhost:8086/filter.s");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("title", "test_" + ns.getTitle()));
nvps.add(new BasicNameValuePair("source", ns.getSource()));
nvps.add(new BasicNameValuePair("category", ns.getCategory()));
nvps.add(new BasicNameValuePair("content", ns.getContent()));
post.setEntity(new UrlEncodedFormEntity(nvps, "gbk"));
HttpResponse response = httpclient.execute(post);
if (response.getStatusLine().getStatusCode() != 200) {
logger.error("Status code is not 200 - "
+ response.getStatusLine());
continue;
}
HttpEntity entity = response.getEntity();
String jstr = EntityUtils.toString(entity);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment