httpclient 302 重定向

  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); HttpClient client = new HttpClient();
    client.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{ //非正常执行,异常处理代码。。 }
上一篇:win8.1 环境下搭建PHP5.5.6+Apache2.4.7


下一篇:oracle11g 卸载和安装(win7,32位)