HttpClient结合PostMethod调用接口
解决方法:
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://192.168.0.189:8500/short");
post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");// 在头文件中设置转码
post.setRequestHeader("Connection", "close");
NameValuePair[] data = { new NameValuePair("username", this.username), new NameValuePair("passwd", this.passwd))};
post.setRequestBody(data);
client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
String result = new String(post.getResponseBodyAsString().getBytes());
本文链接:http://www.yayihouse.com/yayishuwu/chapter/1419