Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
List<MediaType> mediaTypeList = new ArrayList<>();
mediaTypeList.add(MediaType.APPLICATION_JSON);
//mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8);
mediaTypeList.add(MediaType.TEXT_PLAIN);
mediaTypeList.add(MediaType.ALL);
headers.setAccept(mediaTypeList);
headers.add(HttpHeaders.ACCEPT_ENCODING, "gzip, deflate");
headers.add(HttpHeaders.ACCEPT_LANGUAGE, "Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7");
headers.add(HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36");
headers.add(HttpHeaders.CONTENT_LENGTH,"178");
headers.add(HttpHeaders.CONTENT_TYPE,"application/x-www-form-urlencoded");
headers.add(HttpHeaders.REFERER,"http://www.7dingdong.com/");
headers.add(HttpHeaders.ORIGIN,"http://www.7dingdong.com");
headers.add(HttpHeaders.CONNECTION,"keep-alive");
headers.add(HttpHeaders.HOST, "7ddapi.7dingdong.com");
HttpEntity<String> httpEntity = new HttpEntity<String>("",headers);
StringBuffer paramsURL = new StringBuffer(goLoginUrl);
paramsURL.append("?token=" + token)
.append("&t="+ t)
.append("&device="+ device)
.append("&user_name="+ user_name)
.append("&password="+ password)
.append("&company="+ company)
.append("&api="+ api);
ResponseEntity<Object> response = restTemplate.exchange(
paramsURL.toString(),
HttpMethod.GET,
httpEntity,
Object.class);
ResponseEntity<String> response = restTemplate.postForEntity(goLoginUrl,httpEntity,String.class);
Error:
Exception in thread "main" org.springframework.http.InvalidMediaTypeException: Invalid mime type "application:json;charset=utf8": does not contain '/'
at org.springframework.http.MediaType.parseMediaType(MediaType.java:534)
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:932)
at org.springframework.web.client.HttpMessageConverterExtractor.getContentType(HttpMessageConverterExtractor.java:133)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:90)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:995)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:978)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:737)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:579)
at Login.goLogin(Login.java:268)
at Login.main(Login.java:293)
Caused by: org.springframework.util.InvalidMimeTypeException: Invalid mime type "application:json;charset=utf8": does not contain '/'
at org.springframework.util.MimeTypeUtils.parseMimeType(MimeTypeUtils.java:197)
at org.springframework.http.MediaType.parseMediaType(MediaType.java:531)
... 10 more
Disconnected from the target VM, address: '127.0.0.1:54273', transport: 'socket'
–
From the error you can understand that mime type is wrong application:json;charset=utf8
It should be application/json;charset=utf8
You should use APPLICATION_JSON_UTF8_VALUE
instead of MediaType.APPLICATION_JSON
:
mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8_VALUE);
–
you have to use MediaType.APPLICATION_JSON_VALUE
as the media type for application json application/json
MediaType.APPLICATION_JSON_VALUE
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.