Padawan
Padawan

Reputation: 144

HttpPost add to url HTTP/1.1

This void for creating the 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:

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

but my postMethod will become after initializing:

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

what is HTTP/1.1 ? and how can I delete it??

Upvotes: 0

Views: 942

Answers (1)

Saeed Hassanvand
Saeed Hassanvand

Reputation: 977

If you print postMethod, you see:

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

HTTP/1.1 is a part of every HTTP request structure. HTTP/1.1 show that this request is based on 1.1 version of HTTP. This is not part of your API address (/location-service/add).

This is an example of a POST request:

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

Upvotes: 1

Related Questions