示例#1
0
  @Override
  public Result multPartPost(
      HttpUrl url,
      String encoding,
      String cookie,
      Map<String, String> headers,
      String fileParamName,
      String fileName,
      byte[] fileBytes) {
    String realUrl = url.getRenderedUrl();
    PostMethod method = new PostMethod(realUrl);
    List<Part> partList = new ArrayList<Part>();

    if (url.getQueryParam() != null) {
      for (Entry<String, String> entry : url.getQueryParam().entrySet()) {
        partList.add(new StringPart(entry.getKey(), entry.getValue()));
      }
    }
    if (fileBytes != null) {
      partList.add(
          new FilePart(
              fileParamName,
              new ByteArrayPartSource(fileName, fileBytes),
              getContentType(fileName, fileBytes),
              "UTF-8"));
    }
    method.setRequestEntity(
        new MultipartRequestEntity(
            partList.toArray(new Part[partList.size()]), method.getParams()));
    Result result = excuteMethod(method, cookie, headers);
    result.setResultEncoding(encoding);
    return result;
  }
示例#2
0
 @Override
 public Result post(HttpUrl url, String encoding, String cookie, Map<String, String> headers) {
   String realUrl = url.getRenderedUrl();
   PostMethod method = new PostMethod(realUrl);
   if (url.getQueryParam() != null) {
     for (Entry<String, String> entry : url.getQueryParam().entrySet()) {
       method.addParameter(new NameValuePair(entry.getKey(), entry.getValue()));
     }
   }
   Result result = excuteMethod(method, cookie, headers);
   result.setResultEncoding(encoding);
   return result;
 }
示例#3
0
 public void execute(Context context, Navigator navigator) {
   TurbineRunDataInternal runData =
       (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(request);
   ParameterParser param = runData.getParameters();
   String url = param.getString("url");
   HttpUrl httpUrl = UrlParseUtils.parseUrl(url);
   for (String key : param.keySet()) {
     if (!"url".equals(key)) {
       httpUrl.getQueryParam().put(key, param.getString(key));
     }
   }
   url = httpUrl.toUrlString();
   runData.redirectToLocation(url);
 }
示例#4
0
 @Override
 public Result get(HttpUrl url, String encoding, String cookie, Map<String, String> headers) {
   String realUrl = url.toUrlString();
   GetMethod method = new GetMethod(realUrl);
   Result result = excuteMethod(method, cookie, headers);
   result.setResultEncoding(encoding);
   return result;
 }