Browse Source

调整api执行请求

master
xyiege 3 years ago
parent
commit
ef75f219e5
  1. 3
      .gitignore
  2. 15
      src/main/java/cn/chjyj/szwh/utils/RequestUtils.java
  3. 11
      src/test/java/cn/chjyj/szwh/ApiTest.java

3
.gitignore

@ -25,4 +25,5 @@ hs_err_pid*
.idea/
.mvn/
target/
target/
json/

15
src/main/java/cn/chjyj/szwh/utils/RequestUtils.java

@ -1,5 +1,6 @@
package cn.chjyj.szwh.utils;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@ -17,6 +18,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Calendar;
import java.util.Map;
/**
@ -47,13 +49,14 @@ public class RequestUtils {
httpcon.connect();
//获取返回的字符
InputStream inputStream = httpcon.getInputStream();
int size = inputStream.available();
byte[] bs = new byte[size];
inputStream.read(bs);
//请求结果写入
String filename =String.valueOf(Calendar.getInstance().getTimeInMillis());
SzFileUtils.createFile(inputStream,filename);
//字节转为utf-8
String message = new String(bs, "UTF-8");
System.out.println("url ret string :"+message);
jsonObject = JSONObject.parseObject(message);
String message=SzFileUtils.readJson(filename);
if(message!=null){
jsonObject = JSONObject.parseObject(message);
}
logger.info("respone message :"+message);
}catch (IOException ex){
// 罗列出明细错误

11
src/test/java/cn/chjyj/szwh/ApiTest.java

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save