HttpPost添加到URL HTTP / 1.1

时间:2018-11-28 11:34:25

标签: java spring post apache-httpclient-4.x fluent

创建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?以及如何删除它?

1 个答案:

答案 0 :(得分:1)

如果打印postMethod,则会看到:

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

HTTP/1.1是每个HTTP请求结构的一部分。 HTTP/1.1显示此请求基于1.1的{​​{1}}版本。这不属于您的API地址(HTTP)。

这是一个/location-service/add请求的示例:

POST