Example #1
0
 /**
  * get
  *
  * @param url
  * @param params
  * @return
  * @throws ApiException
  */
 public static String get(String url, PostParameter[] params, String token) throws IOException {
   if (null != params && params.length > 0) {
     String encodedParams = PostParameter.encodeParameters(params);
     if (-1 == url.indexOf("?")) {
       url += "?" + encodedParams;
     } else {
       url += "&" + encodedParams;
     }
   }
   GetMethod getmethod = new GetMethod(url);
   return httpRequest(getmethod, token);
 }
Example #2
0
 /** 处理http deletemethod请求 */
 public static String delete(String url, PostParameter[] params, String token) throws IOException {
   if (0 != params.length) {
     String encodedParams = PostParameter.encodeParameters(params);
     if (-1 == url.indexOf("?")) {
       url += "?" + encodedParams;
     } else {
       url += "&" + encodedParams;
     }
   }
   DeleteMethod deleteMethod = new DeleteMethod(url);
   return httpRequest(deleteMethod, token);
 }
Example #3
0
 /**
  * 支持multipart方式上传
  *
  * @param url
  * @param params
  * @param token
  * @return
  * @throws ApiException
  */
 public static String multPartURL(String url, PostParameter[] params, String token)
     throws IOException {
   PostMethod postMethod = new PostMethod(url);
   if (params != null) {
     Part[] parts = new Part[params.length];
     int i = 0;
     for (PostParameter entry : params) {
       if (entry.isFile()) {
         parts[i++] =
             new ByteArrayPart(
                 entry.getFile().getContent(), entry.getName(), entry.getFile().getMimeType());
       } else {
         parts[i++] = new StringPart(entry.getName(), entry.getValue(), DEFAULTCHAESET);
       }
     }
     postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
   }
   return httpRequest(postMethod, token);
 }