[英]Error 404 with Java HttpClient
我正在使用Java HttpClient程序包發出http請求。 但是我得到404。當我嘗試使用curl進行相同的請求時,它工作正常。 這是curl請求-
curl -i -X POST http://api/endpoint -H "Content-Type: application/json" -d 'content'
這是我用來實現上述curl請求的Java代碼-
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("http://api/endpoint");
post.setHeader("Content-type", "application/json");
post.setEntity(new StringEntity(content));
HttpResponse response = client.execute(post);
logger.info("Response Code : "
+ response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
logger.info("Response details "+result);
運行此Java代碼時,我看到錯誤404未找到。 可能是什么問題?
刪除post.setHeader(“ Accept”,“ application / json”);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.