report
parent
919c05ae33
commit
3e00a693da
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue