首页 > Web开发 > 详细

httpclient 302 重定向

时间:2015-02-26 16:33:02      阅读:340      评论:0      收藏:0      [点我收藏+]
  1. 主要是由于页面可能不是通过 request.sendRedirect跳转的,可能通过js  location跳转的。所以需要拿跳转后的 地址,重新发送请求。。。如下所示
  2.  if (status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY) {
     Header locationHeader = hm.getResponseHeader("location");
     String location = null;
     if (locationHeader != null) {
     location = locationHeader.getValue();
     GetMethod redirect=new GetMethod(location);  
     int status_ =   http.executeMethod(redirect); 
    if (status_ != HttpStatus.SC_OK) {
    throw new JobExecutionException("[执行结果=失败][状态码=" + status + "]" + (hm.getStatusLine() == null ? "" : "[信息=" + hm.getStatusText() + "]"));
    }
     //responseBody = getPostResponse(location, parts);// 用跳转后的页面重新请求。
      }
      } else if (status == HttpStatus.SC_OK) {
        responseBody = hm.getResponseBodyAsString();
     }else{
        //非正常执行,异常处理代码。。
     }

     

httpclient 302 重定向

原文:http://www.cnblogs.com/Struts-pring/p/4301443.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!