Ejemplo n.º 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;
  }
Ejemplo n.º 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;
 }