我正在尝试使用带有阿拉伯字符的 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 代码进行哪些更新,以便编码工作?
1 回答
尚方宝剑之说
TA贡献1788条经验 获得超4个赞
改变这一行:
$headers = "charset=utf-8; Content-type: text/xml";
到:
$headers = array("Content-type:text/xml; charset=utf-8");
它应该工作。
- 1 回答
- 0 关注
- 146 浏览
添加回答
举报
0/150
提交
取消