Package org.lilystudio.httpclient

Examples of org.lilystudio.httpclient.GetMethod


      url = "http" + url.substring(4);
    } else {
      isGet = true;
      addParameter(relay, url, encoding);
    }
    IMethod httpMethod = isGet ? new GetMethod(url) : new PostMethod(url);
    // 设置客户端特殊的信息
    httpMethod.setRequestHeader("If-None-Match", request
        .getHeader("If-None-Match"));
    httpMethod.setRequestHeader("If-Modified-Since", request
        .getHeader("If-Modified-Since"));
    // 取出服务器端可能用到的Cookie信息
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
      StringBuilder s = new StringBuilder(64);
      for (Cookie cookie : cookies) {
        String name = cookie.getName();
        if (!name.equals("JSESSIONID")) {
          s.append(name).append('=').append(cookie.getValue()).append(';');
        }
      }
      UserInformation info = relay.getUserInformation(false);
      if (info != null) {
        Object o = info.getProperty(SESSION_COOKIE_KEY);
        if (o != null) {
          s.append(o);
        }
      }
      int len = s.length();
      if (len > 0) {
        s.setLength(len - 1);
      }
      httpMethod.setRequestHeader("Cookie", s.toString());
    }
    HttpClient httpClient = new HttpClient();
    httpClient.setAutoDecode(true);
    try {
      if (param != null) {
        if (!isGet) {
          PostMethod method = (PostMethod) httpMethod;
          int size = param.size();
          for (int i = 0; i < size; i++) {
            Parameter item = param.get(i);
            Object value = item.getValue(relay);
            method.addRequestBody(item.name, value != null ? URLDecoder.decode(
                value.toString(), encoding) : "");
          }
        }
      }
      while (true) {
        // 计算是否需要跳转
        int statusCode = 0;
        statusCode = httpClient.execute(httpMethod);
        if (statusCode == HttpServletResponse.SC_MOVED_PERMANENTLY
            || statusCode == HttpServletResponse.SC_MOVED_TEMPORARILY) {
          String locationHeader = httpClient.getResponseHeader("Location");
          if (locationHeader != null) {
            httpMethod = new GetMethod(locationHeader);
            continue;
          }
        }
        response.setStatus(statusCode);
        break;
View Full Code Here

TOP

Related Classes of org.lilystudio.httpclient.GetMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.