我将Apache Http Client从3.x切换到4.x。
对于旧版本,我使用以下命令设置内容charset。
constructor(props) {
super(props);
const { data, image0, image1, image2, image3, image4 } = this.props;
this.state = {
data : data,
image0: image0,
image1: image1,
image2: image2,
image3: image3,
image4: image4,
};
}
renderList = () => {
const { data } = this.state;
const List = data.map((item, index) => {
return (
<Card
key={index}
data={item}
preview={this.state[`image${index}`]}
/>
);
})
}
...
现在我切换到4.x,但是我无法找到设置http.protocol.content-charset的方法。
https://github.com/pytorch/pytorch/blob/master/aten/src/THNN/generic/SpatialAdaptiveAveragePooling.c
From above file, can not find what is the value of stride
/* strides */
istrideD = input->stride(dimD);
istrideH = input->stride(dimH);
istrideW = input->stride(dimW);
答案 0 :(得分:1)
全局协议字符集参数HC 3.x很傻。
使用ContentType
来赋予HttpEntity
的属性,以便正确编码/解码实体内容。
CloseableHttpClient client = HttpClients.custom()
.build();
HttpPost httpPost = new HttpPost("https://httpbin.org/post");
httpPost.setEntity(new StringEntity("stuff", ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
try (CloseableHttpResponse response = client.execute(httpPost)) {
HttpEntity entity = response.getEntity();
if (entity != null) {
ContentType contentType = ContentType.getOrDefault(entity);
try (Reader reader = new InputStreamReader(
entity.getContent(),
contentType.getCharset() != null ? contentType.getCharset() : StandardCharsets.UTF_8)) {
}
}
}