简体   繁体   English

HttpPost添加到URL HTTP / 1.1

[英]HttpPost add to url HTTP/1.1

This void for creating the POST. 这对于创建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 - its String like: methodName-其字符串,例如:

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

but my postMethod will become after initializing: 但我的postMethod将在初始化后变为:

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

what is HTTP/1.1 ? 什么是HTTP / 1.1? and how can I delete it?? 以及如何删除它?

If you print postMethod , you see: 如果打印postMethod ,则会看到:

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

HTTP/1.1 is a part of every HTTP request structure. HTTP/1.1是每个HTTP请求结构的一部分。 HTTP/1.1 show that this request is based on 1.1 version of HTTP . HTTP/1.1表明此请求基于HTTP 1.1版本。 This is not part of your API address ( /location-service/add ). 这不属于您的API地址( /location-service/add )。

This is an example of a POST request: 这是POST请求的示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM