如何在PHP中使用cURL发布阿拉伯语文本


How to post arabic text using cURL in PHP?

如何在PHP中使用cURL发布阿拉伯语文本?

$postData = array(
    'msg' => 'مرحبا'
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

普通应用程序/x-www-form-urlencoded类型中的CURL POST。

所以我认为你需要设置字符集。

你可以尝试将其与其他选项一起添加吗:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml;charset=utf-8"));

希望这有帮助:)

使用urlencode对发布的数据进行编码。。。

尝试按如下方式设置标题和选项:

$header = array("Content-type:text/xml; charset=utf-8");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);

然后你可以发布你的数据。

最后,不要忘记承诺:

curl_setopt($ch, CURLOPT_POSTFIELDS, "<commit />");

(这取自一个工作实现)

使用get方法时,请尝试此操作。

<?php
//step1
$cSession = curl_init(); 
//step2
curl_setopt($cSession,CURLOPT_URL,"http://www.google.com/search?q=curl");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false); 
//step3
$result=curl_exec($cSession);
//step4
curl_close($cSession);
//step5
echo $result;
?>