这对于创建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