【发布时间】:2022-08-04 02:27:58
【问题描述】:
我有示例代码 sn-p。它返回 400 错误。使用 OkHttp3 客户端使用相同的 BasicAuth 凭据效果很好。这里缺少什么?
```
String BASIC_AUTHORIZAION = \"Basic *********\"; // masked
String reportRequest = \"{***}\"; //json string
CloseableHttpClient client = HttpClientBuilder.create().build();
FormBodyPart bodyPart = FormBodyPartBuilder
.create()
.setName(\"ReportRequest\")
.setBody(new StringBody(reportRequest, ContentType.APPLICATION_JSON))
.build();
HttpEntity requestEntity = MultipartEntityBuilder
.create()
.addPart(bodyPart)
.addTextBody(\"type\", ContentType.APPLICATION_JSON.toString())
.build();
HttpUriRequest httpPost = RequestBuilder
.post(MPG_MESSAGE_STATUS_REPORT_URL)
.addHeader(\"Content-Type\", ContentType.MULTIPART_FORM_DATA.toString())
.addHeader(\"Authorization\", BASIC_AUTHORIZAION)
.setEntity(requestEntity)
.build();
HttpResponse response = client.execute(httpPost);
标签: java okhttp basic-authentication