Commit ff36fb7b authored by 张俊's avatar 张俊

代码优化

parent 9191b2e8
......@@ -31,7 +31,7 @@ public class HttpUtil {
/**
* 发起 post 请求,并对出参进行解压缩
* 发起 post 请求
*/
public static String sendPost(String httpUrl, String content) {
StringBuffer sb = new StringBuffer();
......@@ -54,8 +54,6 @@ public class HttpUtil {
conn.setRequestProperty("Connection", "Keep-Alive");
// 设置文件类型:
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
// 设置文件字符集:
conn.setRequestProperty("Charset", "UTF-8");
// 转换为字节数组
......@@ -69,16 +67,15 @@ public class HttpUtil {
out.write(data);
// 请求返回的状态
if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
// 请求返回的数据,解压缩
// 请求返回的数据
InputStream is = conn.getInputStream();
GZIPInputStream gzis = new GZIPInputStream(is);
InputStreamReader reader = new InputStreamReader(gzis, "UTF-8");
BufferedReader br = new BufferedReader(reader);
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
String readLine = new String();
BufferedReader responseReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine);
}
System.out.println("第三方返回的zip解压缩之后的报文:" + sb);
responseReader.close();
System.out.println("前置机返回第三方解压之后数据:" + sb);
return sb.toString();
} else {
System.out.println("请求失败!!!");
......
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