|
|
@@ -51,7 +51,7 @@ public class HttpUtils {
|
|
|
httpPost.addHeader("Content-type", "application/json");
|
|
|
httpPost.setHeader("Accept", "application/json");
|
|
|
httpPost.setEntity(new StringEntity(JSON.toJSONString(map), Charset.forName("UTF-8")));
|
|
|
- httpPost.setHeader("Authorization","26a418106d92a32ea713f4fcec9e0ce6");
|
|
|
+
|
|
|
HttpResponse response = null;
|
|
|
try {
|
|
|
response = httpClient.execute(httpPost);
|
|
|
@@ -80,4 +80,41 @@ public class HttpUtils {
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param url 地址
|
|
|
+ * @param map 参数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String httpPostToStr(String url,Map<String, Object>map){
|
|
|
+ HttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ httpPost.addHeader("Content-type", "application/json");
|
|
|
+ httpPost.setHeader("Accept", "application/json");
|
|
|
+ httpPost.setEntity(new StringEntity(JSON.toJSONString(map), Charset.forName("UTF-8")));
|
|
|
+ httpPost.setHeader("Authorization","26a418106d92a32ea713f4fcec9e0ce6");
|
|
|
+ HttpResponse response = null;
|
|
|
+ try {
|
|
|
+ response = httpClient.execute(httpPost);
|
|
|
+ if (null == response || response.getStatusLine() == null) {
|
|
|
+ throw new Exception("Post Request For Url[{}] is not ok. Response is null");
|
|
|
+ } else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
|
|
+ throw new Exception("Post Request For Url[{}] is not ok. Response Status Code is {"+response.getStatusLine().getStatusCode()+"}");
|
|
|
+ }
|
|
|
+ } catch (ClientProtocolException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String resultString=null;
|
|
|
+ try {
|
|
|
+ resultString = EntityUtils.toString(response.getEntity(),"UTF-8");
|
|
|
+ } catch (ParseException | IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return resultString;
|
|
|
+ }
|
|
|
+
|
|
|
}
|