我正在尝试使用带有阿拉伯字符的 PHP 发送 XML CURL 请求,但存在编码问题!
我正在使用以下脚本:
$input_xml = '<?xml version="1.0" encoding="utf-8"?><request><Name>تجربة رسالة</Name></request>';
$headers = "charset=utf-8; Content-type: text/xml";
$url = "http://www.test.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $input_xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
curl_close($ch);
一旦我尝试使用以下命令从服务器终端发出请求,编码就正确了:
echo '<?xml version="1.0" encoding="UTF-8"?><request><Name>تجربة النص</Name></request>' | curl -X POST -H 'Content-type: text/xml; charset=utf-8' -d @- http://test.com
请您建议应该对 PHP 代码进行哪些更新,以便编码工作?
尚方宝剑之说