1.问题:报文要求使用GBK编码,返回的statusText字段中也有中文,如果使用默认的FeignClient发送请求是没有办法的
@FeignClient(name = "testFeign",url="127.0.0.1:6789" ,configuration = FeignDecoder.class) public interface TestFeign { @PostMapping(consumes = MediaType.APPLICATION_XML_VALUE,produces = MediaType.APPLICATION_XML_VALUE) String getBalance(@RequestBody String params); } consumes:该接口只接受指定的数据类型 produces:指定返回的数据类型,指定为xml的类型
2:返回字段中设置GBK编码
继承Feign的Decoder接口,示例如下:
@Override public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException { try(InputStream inputStream = response.body().asInputStream()) { byte[] bodyBytes = IOUtils.toByteArray(inputStream); String bodyStrArr = new String(bodyBytes, "GBK"); return bodyStrArr; } }
3:请求编码的话 ,我改都不行,最后没有办法了,使用的是RestTemplate的封装了一个 重写了HttpMessageConverter才行的
4:疑惑如下:
实现Encoder接口的话,好像没有用,
实现RequestInterceptor接口的话,重新设置header,包括设置RequestCharset的encoder方法都没有用,有知道的大哥可以联系我
按理说我再xml的头部中指定了<?xml version="1.0" encoding="GBK"?>编码,还是用的是application/xml这种,应该报文里的中文是按照GBK进行编码的,但是他好像还是按照UTF-8进行编码的,这个地方也没明白,有了解的也可以联系我