简体   繁体   English

如何使用apache httpclient fluent 4.3.2在请求中设置charset

[英]How to set the charset in request using apache httpclient fluent 4.3.2

Request.config(CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8) and Request.elementCharset(charset) are Deprecated. Request.config(CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8)Request.elementCharset(charset)已弃用。

Now how to set the request charset to utf-8 with fluent? 现在如何使用流畅的方式将请求字符集设置为utf-8?

Request.Post(url)
    .useExpectContinue()
    .version(HttpVersion.HTTP_1_1)
    .bodyString("Important stuff", ContentType.DEFAULT_TEXT)
    .execute().returnContent().asBytes();

That would be the right way doing it 这将是正确的做法

Request.Post("someurl")
        .useExpectContinue()
        .version(HttpVersion.HTTP_1_1)
        .bodyString("Important stuff", ContentType.create("text/plain", Consts.UTF_8))
        .execute()
        .returnContent().asBytes();    

尝试

Request.setHeader(CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Apache HttpClient 4.5中设置默认超时? (流利) - How to set default timeout in Apache HttpClient 4.5? (fluent) 使用apache httpclient如何为http请求设置cookie - Using apache httpclient how to set cookie for http request 使用Apache HttpClient如何在请求和响应上设置TIMEOUT - Using Apache HttpClient how to set the TIMEOUT on a request and response 如何使用Apache httpclient 4. *和PoolingHttpClientConnectionManager为每个请求设置超时? - How to set timeout for each request using Apache httpclient 4.* with PoolingHttpClientConnectionManager? Apache HttpClient:使用Fluent API时如何获取重定向位置? - Apache HttpClient: how to get redirect locations when using Fluent API? "如何使用 Apache HttpClient 发布 JSON 请求?" - How to POST JSON request using Apache HttpClient? apache httpclient5 多部分请求 (kotlin) 的编码/字符集问题 - Encoding/charset issues on apache httpclient5 multipart request (kotlin) 使用Apache HttpClient的SOAP请求 - SOAP request using Apache HttpClient 同时使用apache httpclient 4.3.2和httpclient 4.1.2 - Use apache httpclient 4.3.2 and httpclient 4.1.2 at the same time 使用Java Apache HttpClient Fluent API的Cookie管理 - Cookie management using the Java Apache HttpClient Fluent API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM