作者:风行汽车-赣州景通4S店 | 来源:互联网 | 2023-05-16 21:58
1.httpclient为4.X
2.源码为
HttpClient httpClient = new HttpClient();
//设置代理服务器地址和端口 ,在ie浏览器可以看到
httpClient.getHostConfiguration().setProxy("127.0.0.1", 8080);
PostMethod method = new PostMethod(url);
//设置传输的参数data、code、token
((PostMethod) method).addParameter("data", "");
((PostMethod) method).addParameter("code", "123456");
((PostMethod) method).addParameter("token", “”);
HttpMethodParams param = method.getParams();
//设置参数的编码
param.setContentCharset("UTF-8");
httpClient.executeMethod(method);
//获取返回的状态
System.out.println(method.getStatusLine());
//获取返回的内容
System.out.println(method.getResponseBodyAsString());