httpclient返回400

注:只是解决本问题的方法,具体场景具体分析。

背景:
第三发要求替换域名,替换后就报400

报错如下:
HttpResponseProxy{HTTP/1.1 400 Bad Request [Date: Mon, 29 Jun 2020 07:59:53 GMT, Content-Type: application/json, Content-Length: 137, Connection: keep-alive, X-Frame-Options: DENY, Strict-Transport-Security: max-age=86400, X-Content-Type-Options: nosniff, Content-Security-Policy: frame-ancestors ‘none’, X-XSS-Protection: 1, Set-Cookie: TS01b31b7c=013d2d1d96d0148d27cd14386f22f8263e541aea9ddea9ac598e3ff7204b83a4c6af553f70b3fa948add673266f086a9a667c0e19c; Path=/, Vary: Accept-Encoding, Set-Cookie: ppnet_4322=!dEVMocnEmtMSXBQ8CfywxFgCyN/QO9OS8s5W9WN/0NXut2egXzhvwGHxJarWt1O3yNIhJbnMVi+44w==; path=/; Httponly; Secure] ResponseEntityProxy{[Content-Type: application/json,Content-Length: 137,Chunked: false]}}

解决方法:
改之前:



        HttpPost  httpPost = new HttpPost(url);
        httpPost.addHeader("Content Type","application/xml");
        httpPost.addHeader("Authorization",jpHeaderRequest.getAuthorization());
        httpPost.addHeader("X-Client-Request-Id",jpHeaderRequest.getRequestId());
        httpPost.addHeader("X-Client-Id",jpHeaderRequest.getClientId());
        httpPost.addHeader("X-Token",jpHeaderRequest.getToken());

改之后:



        httpPost.addHeader("Authorization",jpHeaderRequest.getAuthorization());
        httpPost.addHeader("X-Client-Request-Id",jpHeaderRequest.getRequestId());
        httpPost.addHeader("X-Client-Id",jpHeaderRequest.getClientId());
        httpPost.addHeader("X-Token",jpHeaderRequest.getToken());
去掉Content Type解决。

你可能感兴趣的:(httpclient返回400)