模拟提交数据到其他公司api接口,代码如下,提交到后台后返回:{"error":"Cannot read property 'enable' of null"},服务器500错误 ;通过fiddler抓取提交的数据,在fiddler重新提交又是正常的,求助高手啊。
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
Content-Length: 49
Date: Sun, 03 May 2020 01:29:59 GMT
X-XSS-Protection: 1;mode=block
Strict-Transport-Security: max-age=31536000
{"error":"Cannot read property 'enable' of null"}
fiddler不做任何修改重新提交:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 63
Date: Sun, 03 May 2020 01:31:47 GMT
X-XSS-Protection: 1;mode=block
Strict-Transport-Security: max-age=31536000
{"result":"5eae1f037eab9e653ce863b8","errcode":0,"errmsg":"OK"}
代码如下:
public static HttpResponse sendAddOrderJsonPost(String url, String json, UserAuth userAuth) {
HttpResponse response = null;
HttpPost post = new HttpPost(url);
post.setConfig(HttpsGlobal.config);
post.setHeader("Host", userAuth.getHost());
post.setHeader("Connection", "keep-alive");
post.setHeader("Accept", "application/json, text/plain, /");
post.setHeader("Origin", userAuth.getOrigin);
post.setHeader("User-Agent", userAuth.getUser_agent());
post.setHeader("Content-Type", "application/json; charset=UTF-8");
post.setHeader("Referer", url);
post.setHeader("Accept-Encoding", "gzip, deflate");
post.setHeader("Accept-Language", "zh-cn-#hans");
post.setHeader("Cookie", userAuth.getCookies());
try {
StringEntity requestEntity = new StringEntity(json, "UTF-8");
post.setEntity(requestEntity);
response = HttpsGlobal.client.execute(post);
} catch (SocketTimeoutException e1) {
HttpsGlobal.logger.error("SocketTimeoutException!");
} catch (ConnectTimeoutException e2) {
HttpsGlobal.logger.error("ConnectTimeoutException");
} catch (ConnectException e3) {
HttpsGlobal.logger.error("ConnectException");
} catch (IOException e4) {
HttpsGlobal.logger.error("IOException");
} catch (Exception e5) {
HttpsGlobal.logger.error("Exception");
}
return response;
}