Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Spring RestTemplate中删除字符集?_Spring_Spring Boot_Http_Resttemplate - Fatal编程技术网

如何从Spring RestTemplate中删除字符集?

如何从Spring RestTemplate中删除字符集?,spring,spring-boot,http,resttemplate,Spring,Spring Boot,Http,Resttemplate,当我发布表单请求时,spring正在添加字符集,如application/x-www-form-urlencoded;charset=UTF-8,导致使用restful服务时出现问题。如何将字符集从RestTemplate中删除到,以便内容类型完全是应用程序/x-www-form-urlencoded?FormHttpMessageConverter进行大量验证,以确保您使用的MediaType具有有效的字符集。我会尝试将其子类化并注册一个新的转换器(尽管有很多私有方法),或者手动将多值映射转换

当我发布表单请求时,spring正在添加字符集,如
application/x-www-form-urlencoded;charset=UTF-8
,导致使用restful服务时出现问题。如何将字符集从RestTemplate中删除到,以便内容类型完全是
应用程序/x-www-form-urlencoded

FormHttpMessageConverter
进行大量验证,以确保您使用的MediaType具有有效的字符集。我会尝试将其子类化并注册一个新的转换器(尽管有很多私有方法),或者手动将
多值映射转换为字符串有效负载(
StringHttpMessageConverter
对媒体类型的限制要小得多)

HttpHeaders=newhttpheaders();
headers.setContentType(MediaType.APPLICATION\u FORM\u URLENCODED);
HttpEntity实体=新的HttpEntity(“参数1=值1”,标题);
String result=restemplate.postForObject(url、实体、String.class);

问题尚不清楚。能否提供更多数据,如日志、样本代码等。这篇文章中似乎有一个问题:您使用哪种方法发送请求?您的请求主体是如何定义的(字符串、映射)?因此,使用什么转换器来编码您的请求正文?FormMessage converter,我实际上已经浏览了代码。似乎spring明确地设置了转换器中的字符集。没有办法。顺便说一句,我使用了多值映射,同时使用了postforentity和exchange。我最终将MediaType、HttpHeaders子类化来解决这个问题。但是,我认为应该有一种方法来排除添加到实际请求中的contentType。