我正在處理Spring RestTemplate,並在執行下面的代碼後得到InvalidMediaTypeException
。當我在RestClient應用程序中執行相同的服務時,我收到了有效的回覆。請幫助。Spring - RestTemplate拋出InvalidMediaTypeException
ResponseEntity<String> response = restTemplate.exchange(restUrl,HttpMethod.valueOf(method), new HttpEntity<byte[]>(headers), String.class);
以下是堆棧跟蹤。
org.springframework.http.InvalidMediaTypeException: Invalid media type "multipart/mixed;boundary=simple boundary;charset=UTF-8": Invalid token character ' ' in token "simple boundary"
at org.springframework.http.MediaType.parseMediaType(MediaType.java:730)
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:305)
at org.springframework.web.client.HttpMessageConverterExtractor.getContentType(HttpMessageConverterExtractor.java:113)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:84)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:687)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:673)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:491)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:446)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:393)
at com.restclient.helper.RestHelper.getResponse(RestHelper.java:28)
你有什麼標題? – Avi
content-type:application/x-www-form-urlencoded是標題。該方法是GET並將所有參數作爲URL的一部分傳遞。 –