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