如何解決使用restTemplate進行feign調(diào)用new HttpEntity<>報錯問題
restTemplate進行feign調(diào)用new HttpEntity<>報錯
問題背景
今天才知道restTemplate可以直接調(diào)用feign,高級用法呀,但使用restTemplate進行feign調(diào)用new HttpEntity<>報錯了標(biāo)紅了

導(dǎo)入的錯包為:
import org.apache.http.HttpEntity;
HttpEntity<>標(biāo)紅解決方案
1 原來是因為引錯了包,在標(biāo)紅處使用快捷鍵alt+enter,選第二個改變類型


更改新包為:
import org.springframework.http.ResponseEntity;
心得
不同依賴導(dǎo)致的問題,要多注意
resttemplate調(diào)用HttpEntity 產(chǎn)生報錯
項目場景
resttemplate調(diào)用HttpEntity 產(chǎn)生報錯
傳輸過程
問題描述
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
*/
//應(yīng)該把map換成NameValuePair[] data = { new NameValuePair("xmlData",string) };
NameValuePair[] data = { new NameValuePair("xmlData",string) };
HttpEntity<String> httpEntity = new HttpEntity(data, headers);
//這樣就可以了解決方案
應(yīng)該把hashmap 換成 MultiValueMap 就可以了
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
IDEA 2020.1 for Mac 下載安裝配置及出現(xiàn)的問題小結(jié)
這篇文章主要介紹了IDEA 2020.1 for Mac 下載安裝配置及出現(xiàn)的問題小結(jié),本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03
Java如何獲取List<String>中的String詳解
工作了這么長時間了,一直沒有記錄的習(xí)慣,以至于導(dǎo)致我即便是查過的東西總會忘記,下面這篇文章主要給大家介紹了關(guān)于Java如何獲取List<String>中String的相關(guān)資料,需要的朋友可以參考下2022-02-02
SpringBoot 使用Mybatis分頁插件實現(xiàn)詳解
這篇文章主要介紹了SpringBoot 使用Mybatis分頁插件實現(xiàn)詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-10-10

