简体   繁体   English

对Java POST调用的HTTP错误请求响应

[英]HTTP Bad Request response to Java POST call

I'm attempting to query a REST api using POST requests in a java application. 我正在尝试使用Java应用程序中的POST请求查询REST api。 I think I've set everything correctly, but I keep getting a Bad Request response. 我认为我已经正确设置了所有内容,但是我一直收到错误请求的响应。

HttpPost request = new HttpPost(requestURI);
request.addHeader("accept", "application/json");
request.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
HttpEntity entity = new StringEntity(requestBody + new Integer(PatientId).toString() + "}");
request.setEntity(entity);

The requestBody, accompanied by the number and curly brace, are valid JSON, and the requestURI is copy and pasted straight out of the API documentation, so I know I shouldn't be getting a Bad Request due to those. requestBody以及数字和大括号是有效的JSON,并且requestURI是直接从API文档中复制并粘贴的,因此我知道我不会因为这些原因而收到Bad Request。

Am I missing something in the setup? 我在设置中缺少什么吗?

The Content-Length header is missing. Content-Length标头丢失。 Some servers don't report the correct 4xx error (411 Length Required) and just issue a generic Bad Request error. 某些服务器不会报告正确的4xx错误(所需长度为411),而只会发出一般性的错误请求错误。

最终是我的URI中未包含的随机斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM