最近对接第三方系统,各位铁汁都说来一遍原生http请求,今天 干好对接,给大家安排一手
JSONObject jsonObject = new JSONObject();
jsonObject.put("businessFormNo", businessFormNo);
jsonObject.put("businessFormType", businessFormType);
String url = "http://192.111.11.11:1111/app/restful/api/wms/xxx";
// 添加请求头信息
Map<String, String> heads = new HashMap<>();
// 使用json发送请求
heads.put("Content-Type", "application/json;charset=UTF-8");
// headerMap是添加的请求头,
HttpResponse response = HttpRequest.post(url)
.headerMap(heads, false)
//json变字符串,post的身体
.body(String.valueOf(jsonObject))
//时间 毫秒
.timeout(5 * 60 * 1000)
.execute();
//拿到返回的数据
String body = response.body();‘
//解析body
JSONObject json = JSONObject.fromObject(body);
//获取接口到数据的指定值
String msgCode = json.get("msgCode");
欢迎交流