簡體   English   中英

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表明此請求基於HTTP 1.1版本。 這不屬於您的API地址( /location-service/add )。

這是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