apache http client 4.3 - 如何设置协议版本

时间:2014-02-14 18:22:37

标签: http apache-httpclient-4.x

如果现在不推荐使用setParams和getParams,如何使用http client 4.3在CloseableHttpClient对象或HttpPost对象上设置协议版本?

2 个答案:

答案 0 :(得分:8)

HttpPost post = new HttpPost("/");
post.setProtocolVersion(HttpVersion.HTTP_1_1);

答案 1 :(得分:1)

或使用他们如今喜欢的那种建筑师模式:

final HttpUriRequest request = RequestBuilder.post()
    .setVersion(HttpVersion.HTTP_1_1)
    .setUri(requestURI)
    .addHeader(key, value)
    .... <whaterver more you want to add to the request>         
    .build()
相关问题