HttpGet httpget = new HttpGet(rhzh); ---拿到GET请求
HttpPost httpPost = new HttpPost(rhzh);---拿到POST请求
HttpResponse response = httpclient.execute(httpPost);----提交请求 返回可以相应的对象,相应的对象可以拿到相应回来的数据
下面的是最重要的代码,通过他可以拿到我们的相应体
if (response.getEntity() != null) {
HttpResult httpResult = new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString( response.getEntity(), "UTF-8"));
//可以拿到状态码
System.out.println(httpResult.getCode());
//getBody()可以拿到TICKET
System.out.println(httpResult.getBody());
}
//HttpResul
t需要的参数
Integer code 状态码通过相应对象拿到
response.getStatusLine().getStatusCode() 这个是状态码,
String body 相应体
EntityUtils.toString( response.getEntity(), "UTF-8")这个是 相应体
HttpClient的使用
最新推荐文章于 2022-10-15 23:54:11 发布