Overcome Encoding Problems with PHP, SoapServer, UTF-8, and non English Characters?

谁说胖子不能爱 提交于 2019-12-24 03:19:26

问题


I'm having problems getting PHP to play nicely with SoapServer + UTF-8. Anytime anyone sends a Soap Request with non english characters (i.e. funny quotes, accented characters, etc) the SoapServer throws an exception saying "Bad Request." I've tried decoding the request with utf8_decode and even HTML Special Characters encoded the text. Nothing is working for me.

I'm looking for a point in the right direction because I'm lost at the moment.


回答1:


make sure both SoapServer and SoapClient are initialized with UTF-8 encoding:

$client = new SoapClient("some.wsdl", array('encoding'=>'UTF-8'));
$server = new SoapServer("some.wsdl", array('encoding'=>'UTF-8'));

does the XML of the requests with the "funny quotes, accented characters, etc." validate?




回答2:


An obvious next step would be to verify that the request you receive is actually encoded as UTF-8. A network sniffer like WireShark (or even just a bit of work with a plain old telnet client could work) would let you examine the exact data passed to the server. Look through that and verify that it is actually valid UTF-8.



来源:https://stackoverflow.com/questions/714713/overcome-encoding-problems-with-php-soapserver-utf-8-and-non-english-characte

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