java - RestTemplate encoding issue -


while getting data 1 of web service quote(") coming (?) when use rest template. tested web service in postman on chrome , giving correct characters. tried encoding utf-8, no success.

i checked following encoding web service provider :

cache-control → private connection → close content-encoding → gzip content-length → 3407 content-type → text/xml; charset=iso-8859-1 date → wed, 10 jun 2015 13:35:53 gmt server → google search appliance vary → accept-encoding x-frame-options → sameorigin x-content-type-options → nosniff x-xss-protection → 1; mode=block

here code :

resttemplate resttemplate = new resttemplate();

    httpheaders headers = new httpheaders();     mediatype mediatype = new mediatype("text", "xml", charset.forname("iso-8859-1"));      headers.set("accept", "text/xml; charset=iso-8859-1");     headers.setcontenttype(mediatype);     headers.setacceptcharset(arrays.aslist(charset.forname("utf-8")));     headers.setaccept(arrays.aslist(mediatype));      responseentity<string> res = resttemplate.exchange(gsasearchurl, httpmethod.get, new httpentity<string>(headers), string.class);       system.out.println(res.getbody()); 

you need add httpmessageconverter utf-8 encoded strings resttemplate. you:

    resttemplate.getmessageconverters().add(0, new stringhttpmessageconverter(charset.forname("utf-8"))); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -