大家好,又见面了,我是你们的朋友全栈君。
项目场景:
resttemplate调用HttpEntity 产生报错
传输过程
问题描述:
org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [[Lorg.apache.commons.httpclient.NameValuePair;] and content type [application/x-www-form-urlencoded]
原因分析:
HashMap<String, String> map = new HashMap<>(); map.put("xmlData", "xmlDataInfo"); //上面的map直接塞进request请求里会报错 /** * org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter * found for request type [[Lorg.apache.commons.httpclient.NameValuePair;] and content type [application/x-www-form-urlencoded */ //应该把map换成NameValuePair[] data = { new NameValuePair("xmlData",string) }; NameValuePair[] data = { new NameValuePair("xmlData",string) }; HttpEntity<String> httpEntity = new HttpEntity(data, headers); //这样就可以了
解决方案:
,应该把hashmap 换成 MultiValueMap 就可以了
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127967.html原文链接:https://javaforall.cn