HttpClient方法:
private static void httpClientPost() {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(TEST_URL);
try {
ContentProducer cp = new ContentProducer() {
public void writeTo(OutputStream outstream) throws IOException {
Writer writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write("");
writer.flush();
}
};
post.setEntity(new EntityTemplate(cp));
HttpResponse response = client.execute(post);
System.out.println(EntityUtils.toString(response.getEntity()));
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}