1. 请求接口
/** * 请求接口 * * @param url * @param paramsStr * @param type Connection.Method.POST * @param heads * @return */ public JSONObject sendUpload(String url, String paramsStr, Connection.Method type, Map<String, String> heads) { //发送上传订单请求 String erpUploadResponse = null; try { Connection connection = Jsoup.connect(url).ignoreContentType(true) .header("Accept", "*/*") .header("Content-Type", "application/json; charset=UTF-8") .method(type) .timeout(2000000); if (heads != null) { for (Map.Entry<String, String> entry : heads.entrySet()) { connection.header(entry.getKey(), entry.getValue()); } } if (type == Connection.Method.POST) { connection.requestBody(paramsStr); } erpUploadResponse = connection.execute().body(); } catch (IOException e) { logger.error("## FEITE面单上传接口出错!URL={},param={}, type={}", url, paramsStr, type); } return JSONObject.parseObject(erpUploadResponse); }
2. 请求方式
JSONObject responseJson = sendUpload(erpQueryTraceId, JSON.toJSONString(param), Connection.Method.POST, null);