java中httpclent以post方式提交请求时,http返回码是302重定向时,不自...
接口A:请求地址为http://www.test.com/test
接口A的功能,会把接收到的参数url写入到header的Location属性中
在java中,使用httpclient发送请求,
在以get方式发送请求时,http的返回码是200,自动处理了重定向
在以post方式发送请求时,http的返回码是302,不自动重定向,而且处于占用连接等待状态
此时的处理:
针对返回结果,处理返回码为302的情况
- HttpPost httpPost = new HttpPost(url);
- StringEntity reqEntity = new StringEntity(str);
- HttpResponse response = httpclient.execute(httppost);
- httppost.abort();
-
-
- if (response.getStatusLine().getStatusCode() == 302) {
- String locationUrl=response.getLastHeader("Location").getValue();
- get(locationUrl);
- }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。