Created
December 4, 2012 07:30
-
-
Save hujj0615/4201554 to your computer and use it in GitHub Desktop.
httpclient post example
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
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