yujian
2019-12-02 c0284d7ae6d59aa1146aa5d4123ec7c4b44892da
utils/src/main/java/org/yeshi/utils/HttpUtil.java
@@ -473,6 +473,24 @@
      }
      return "";
   }
   @SuppressWarnings("deprecation")
   public static String post(String url, String entity,String charset) {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(url);
      method.addRequestHeader("Content-Type", "text/html;charset="+charset);
      method.setRequestHeader("Content-Type", "text/html;charset="+charset);
      method.setRequestBody(entity);
      try {
         client.executeMethod(method);
         return convertInputStreamToString(method.getResponseBodyAsStream());
      } catch (HttpException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return "";
   }
   public static String postInputStream(String url, File file) throws FileNotFoundException {
      HttpClient client = new HttpClient();
@@ -583,4 +601,25 @@
      return result;
   }
   /**
    * 获取post返回location
    * @param url
    * @return
    */
   public static String getLocation(String url) {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(url);
      try {
         client.executeMethod(method);
            return method.getResponseHeader("location").getValue();
      } catch (HttpException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return null;
   }
}