|
@@ -2,6 +2,7 @@ package com.persagy.ibms.data.sdk.util;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.client.HttpClient;
|
|
import org.apache.http.client.HttpClient;
|
|
@@ -66,4 +67,37 @@ public class HttpClientUtil {
|
|
String result = os.toString("UTF-8");
|
|
String result = os.toString("UTF-8");
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public synchronized static String post(String url, String content, Map<String,String> headParam) throws Exception{
|
|
|
|
+ return post(url,content,headParam,300000);
|
|
|
|
+ }
|
|
|
|
+ public synchronized static String post(String url, String content, Map<String,String> headParam,Integer timeout) throws Exception {
|
|
|
|
+ HttpPost httpost = new HttpPost(url);
|
|
|
|
+ if (timeout != null) {
|
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout)
|
|
|
|
+ .setSocketTimeout(timeout).build();
|
|
|
|
+ httpost.setConfig(requestConfig);
|
|
|
|
+ }
|
|
|
|
+ StringEntity entity = new StringEntity(content, "UTF-8");
|
|
|
|
+ if(headParam != null && headParam.size()>0){
|
|
|
|
+ headParam.forEach((key,value) ->{
|
|
|
|
+ httpost.addHeader(key,value);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ httpost.setEntity(entity);
|
|
|
|
+ entity.setContentType("application/json");
|
|
|
|
+ HttpResponse httpResponse = client.execute(httpost);
|
|
|
|
+ InputStream is = httpResponse.getEntity().getContent();
|
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
+ int b = -1;
|
|
|
|
+ while ((b = is.read()) != -1) {
|
|
|
|
+ baos.write(b);
|
|
|
|
+ }
|
|
|
|
+ baos.close();
|
|
|
|
+ is.close();
|
|
|
|
+
|
|
|
|
+ String result = baos.toString("UTF-8");
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|