Commit 91807a6a by zhangxingmin

push

parent bf6ae7d5
...@@ -64,5 +64,10 @@ ...@@ -64,5 +64,10 @@
<groupId>com.ibm.icu</groupId> <groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId> <artifactId>icu4j</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -69,6 +69,7 @@ public enum CommonEnum { ...@@ -69,6 +69,7 @@ public enum CommonEnum {
APPROVAL_STATUS_DSH("DSH","待审核"), APPROVAL_STATUS_DSH("DSH","待审核"),
APPROVAL_STATUS_CG("CG","审核成功"), APPROVAL_STATUS_CG("CG","审核成功"),
APPROVAL_STATUS_SB("SB","审核失败"), APPROVAL_STATUS_SB("SB","审核失败"),
APPROVAL_STATUS_JJ("JJ","拒绝"),
//来源类型 //来源类型
SOURCE_TYPE_PC("PC","PC"), SOURCE_TYPE_PC("PC","PC"),
......
package com.yd.common.utils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@Component
public class HttpUtil {
private static final CloseableHttpClient httpClient = HttpClients.createDefault();
public static String get(String url) throws IOException {
HttpGet httpGet = new HttpGet(url);
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
}
}
public static String post(String url, String jsonBody) throws IOException {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
if (jsonBody != null) {
httpPost.setEntity(new StringEntity(jsonBody, StandardCharsets.UTF_8));
}
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment