From 3e00a693da4e772c94925440659044dd73fc4132 Mon Sep 17 00:00:00 2001 From: zhangshanxue Date: Tue, 20 Aug 2019 15:47:13 +0800 Subject: [PATCH] report --- .../java/com/ljsd/jieling/util/http/HttpPool.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/serverlogic/src/main/java/com/ljsd/jieling/util/http/HttpPool.java b/serverlogic/src/main/java/com/ljsd/jieling/util/http/HttpPool.java index 147519e91..3fb4ac895 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/util/http/HttpPool.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/util/http/HttpPool.java @@ -1,5 +1,6 @@ package com.ljsd.jieling.util.http; +import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import com.ljsd.jieling.ktbeans.KTSendBody; import org.apache.http.HttpEntity; @@ -37,7 +38,7 @@ public class HttpPool { return RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(50000).setConnectionRequestTimeout(5000).build(); } - public static void sendPostForm(String url, UrlEncodedFormEntity info) { + public static JSONObject sendPostForm(String url, UrlEncodedFormEntity info) { HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse; int sendTimes = 0; @@ -47,12 +48,14 @@ public class HttpPool { httpPost.setConfig(getRequestConfig()); httpPost.setHeader("Content-Type","application/x-www-form-urlencoded"); httpResponse = httpclient.execute(httpPost); - HttpEntity responseEntity = httpResponse.getEntity(); - EntityUtils.consume(responseEntity); + int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { LOGGER.debug("Http sendPostForm,第" + (sendTimes + 1) + "次调用成功,返回码为:[" + statusCode + "]"); - break; + HttpEntity responseEntity = httpResponse.getEntity(); + String result = EntityUtils.toString(responseEntity,"UTF-8"); + return JSONObject.parseObject(result); + } else { LOGGER.error("Http sendPostForm,第" + (sendTimes + 1) + "次调用出错,返回码为:[" + statusCode + "]"); if (sendTimes + 1 <= maxSendTimes) { @@ -72,7 +75,7 @@ public class HttpPool { sendTimes ++ ; } } while (sendTimes < maxSendTimes); - + return null; } public static void sendPost(String url, String info) {