gpt4 book ai didi

java - HttpPost 添加到 url HTTP/1.1

转载 作者:行者123 更新时间:2023-12-02 10:32:39 25 4
gpt4 key购买 nike

此空白用于创建 POST。

public void doPostRequest(Object input, String methodName) throws IOException {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
String JSON_STRING = writer.writeValueAsString(input);

StringEntity requestEntity = new StringEntity(
JSON_STRING,
ContentType.APPLICATION_JSON);

HttpPost postMethod = new HttpPost(methodName);
postMethod.setEntity(requestEntity);
HttpResponse rawResponse = httpClient.execute(postMethod);
}

}

methodName - 其字符串如下:

http://myservice:8180/location-service/add

但是我的postMethod初始化后会变成:

http://myservice:8180/location-service/sync_api/add HTTP/1.1

什么是 HTTP/1.1?我怎样才能删除它??

最佳答案

如果您打印 postMethod,您会看到:

POST http://myservice:8180/location-service/add HTTP/1.1

HTTP/1.1 是每个 HTTP 请求结构的一部分。 HTTP/1.1 显示此请求基于 HTTP1.1 版本。这不是您的 API 地址 (/location-service/add) 的一部分。

这是 POST 请求的示例:

POST /test/demo_form.php HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2

关于java - HttpPost 添加到 url HTTP/1.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53518514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com