簡體   English   中英

如何使用 Apache http 客戶端發送沒有內容和內容長度 header 的 PUT 請求?

[英]Howto send PUT request without content and Content-Length header with Apache http client?

我想測試(通過自動化測試)服務器(以及所有中間代理)如何響應沒有正文和Content-Length header 的 PUT 請求。

類似於 curl 所做的

curl -XPUT http://example.com

與 Apache HTTP 客戶端(4.5.13)

但如果我沒有指定正文,它看起來總是添加Content-Length header 。 Apache HTTP 客戶端有什么辦法嗎?

已經嘗試過(沒有運氣)

final HttpPut request = new HttpPut(url);
request.removeHeaders("Content-Length");

使用請求攔截器修改標准協議處理器生成的請求

CloseableHttpClient httpClient = HttpClients.custom()
        .addInterceptorLast((HttpRequestInterceptor) (request, context) ->
                request.removeHeaders(HttpHeaders.CONTENT_LENGTH))
        .build();
HttpPut httpPut = new HttpPut("http://httpbin.org/put");
httpClient.execute(httpPut, response -> {
    EntityUtils.consume(response.getEntity());
    return null;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM