[英]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.