HttpPost 添加到 url HTTP/1.1

HttpPost add to url HTTP/1.1

创建 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 显示此请求基于 1.1 版本的 HTTP。这不是您的 API 地址 (/location-service/add) 的一部分。

这是 POST 请求的示例:

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