[英]HttpClient POST request returns status 200 without any body (however it should be). Length of the content is -1
[英]HttpClient Get returns 200 but Post returns 404
我正在使用apache http客户端对同一端点进行Get和Post调用。 Get返回200 OK,但Post返回404 Not Found。 有任何想法吗? 我的设置如下:
HttpClient client = HttpClients.createDefault();
String key = "foo"
HttpGet httpGet = new HttpGet("https://url");
HttpResponse response1 = client.execute(httpGet);
System.out.println(response1.getStatusLine());
HttpEntity entity1 = response1.getEntity();
EntityUtils.consume(entity1);
// Returns 200 OK
String bundle = "{\"foo\":\"bar\"}";
HttpPost httpPost = new HttpPost("https://url");
StringEntity requestEntity = new StringEntity(
bundle,
"application/json",
"UTF-8");
httpPost.setEntity(requestEntity);
HttpResponse response2 = client.execute(httpPost);
System.out.println(response2.getStatusLine());
HttpEntity entity2 = response2.getEntity();
EntityUtils.consume(entity2);
// Returns 404 Not Found
确保服务器的相同URL同时接受POST
和GET
,这可能是因为服务器端点将POST
和GET
视为不同的路由并仅接受GET
,将404
返回到您的POST
请求。 所以这不是你的http客户端的问题,而是服务器的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.