Special characters pose problems with REST webservice communication

最后都变了- 提交于 2019-12-02 05:35:30

Try specifying the desired charset in the StringEntity constructor:

StringEntity entity = new StringEntity(absenceObject.toString(), "UTF-8");
Haphazard

If you control both ends of the pipe, you can encode the REST text as shown here Encoding/decoding REST path parameters

Re: Mark's response

Try specifying the desired charset in the StringEntity constructor:

StringEntity entity = new StringEntity(absenceObject.toString(), "UTF-8");

Note that setting charset after the constructor didn't work for me i.e.

entity.setContentEncoding("UTF-8");

I had to do as Mark said and set it in the constructor.

Michael

byte[] buf = body.getBytes(HTTP.UTF_8);
wr.write(buf, 0, buf.length);

Try this it will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!