我想通过REST获得一些航班信息。 奇怪的是,REST调用是通过邮递员运行的,而不是通过代码运行的(我尝试了Springs Rest模板和apache-s HttpPost,什么都没做)。
我将粘贴apache代码
String body = gson.toJson(dto);
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(URL_FOR_FLIGHTS);
StringEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
CloseableHttpResponse response = client.execute(httpPost);
response.getStatusLine().getStatusCode();
如果我将实体的主体值和标头复制到Postman,则该调用有效,但如果运行此代码,则会返回404。
不需要身份验证。 任何人都知道有什么问题吗?