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/ .idea/
.mvn/ .mvn/
target/ target/
json/

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

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