spring - How to force RestTemplate to send multipart/form-data with UTF-8 encoding -
i struggling have multipart/form-data encoded in utf-8 in resttemplate entity. don't know doing wrong. below posted code
linkedmultivaluemap<string, string> map = new linkedmultivaluemap<>(); map.add("text", text); map.add("id", id); httpheaders httpheaders = new httpheaders(); httpheaders.set("content-type","multipart/form-data;charset=utf-8"); httpentity<linkedmultivaluemap<string, string>> entity = new httpentity<>(map, httpheaders); listenablefuture<responseentity<string>> response = asyncrestoperations .postforentity(url, entity, string.class);
when insert polish letters text parameter, example: "ł" rest template sends "?". can see below, in fact body looks , "ł" gets converted "?":
content-disposition: form-data; name="text" content-type: text/plain;charset=iso-8859-1 content-length: 1 ?
i don't know why not working properly. how change default iso-8859-1 encoding utf-8? appreciated!
cheers.
solution found:
i have modified asyncresttemplate , no longer loses utf-8 encoding. working piece of code:
asyncresttemplate asyncresttemplate = new asyncresttemplate(); list<httpmessageconverter<?>> messageconverters = asyncresttemplate.getmessageconverters(); stringhttpmessageconverter stringmessageconverter = new stringhttpmessageconverter(charset.forname("utf-8")); allencompassingformhttpmessageconverter allencompassingconverter = new allencompassingformhttpmessageconverter(); allencompassingconverter.setcharset(charset.forname("utf-8")); allencompassingconverter.setmultipartcharset(charset.forname("utf-8")); allencompassingconverter.setpartconverters(collections.singletonlist(stringmessageconverter)); (iterator<httpmessageconverter<?>> iterator = messageconverters.iterator(); iterator.hasnext(); ) { httpmessageconverter conv = iterator.next(); if (conv instanceof allencompassingformhttpmessageconverter) { iterator.remove(); } } messageconverters.add(allencompassingconverter); asyncresttemplate.setmessageconverters(messageconverters);
refer answer provided here spring resttemplate charset utf-8 not work
for special character support, need encode data.
Comments
Post a Comment