码上敲享录 > java入门知识分享 > HttpClient结合PostMethod调用接口

HttpClient结合PostMethod调用接口

上一章章节目录下一章 2018-08-06已有1530人阅读 评论(0)

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


0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交