PHP Curl使用非英文字符进行POST请求

5
我有一个关于php curl post的小问题。
我试图向论坛发布一些土耳其字符,但它们没有被正确地发布。
这是我保存文本的方式:
    fwrite($fpp,"\xEF\xBB\xBF");
    fwrite($fpp, $row['template']);
    fclose($fpp);

并且进行发布:


$this->curl = curl_init();
    curl_setopt ( $this->curl, CURLOPT_URL, $this->vb_url . 'newthread.php?' . $url_vars );
    curl_setopt ( $this->curl, CURLOPT_POST, true );
    curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
    curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
    curl_setopt ( $this->curl, CURLOPT_CONNECTTIMEOUT,20);
    curl_setopt ( $this->curl, CURLOPT_TIMEOUT,10);
    curl_setopt ( $this->curl, CURLOPT_HEADER, true );
    curl_setopt ( $this->curl, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
    curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
    curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
    curl_setopt ( $this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1;    en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
   $result = curl_exec ( $this->curl );

这是应该的方式:
“您可以在下方找到章节图片、剧集下载和字幕链接。”
这是发布的方式:
“您可以在下方找到Bölüm图片、dizi下载和altyazı链接。”
谢谢。

2
垃圾邮件发送者?你是怎么得出这个结论的?仅仅因为我在寻求 PHP 函数帮助吗? - gtht90
2个回答

3

来自http://php.net/manual/es/function.curl-setopt.php

尝试添加以下内容:

curl_setopt($this->curl,CURLOPT_HTTPHEADER,array (
    "Content-Type: application/x-www-form-urlencoded; charset=utf-8"
));
< p > @spencercw建议使用application/x-www-form-urlencoded格式< /p >

无法工作。我收到了“由于缺少安全令牌,无法处理您的提交。”的错误提示。 - gtht90
1
我猜你需要一个内容类型为application/x-www-form-urlencoded而不是text/xml - spencercw
你的 $post_fields 变量中是否包含 securitytoken 条目? - seanbreeden
您的提交无法处理,因为缺少安全令牌,这与“application/x-www-form-urlencoded”相同。是的,我有一个securitytaken变量,我使用curl从提交页面获取它。 - gtht90
我对此进行了一些调查,发现有一个建议是在表单提交变量上使用 url_encode()。因此,请尝试删除新的 curl_setopt 并对构成 $post_fields 变量的每个字段使用 url_encode - seanbreeden
论坛上发布的“no luck :(”是这样的:%EF%BB%BF%5Bimg%5Dhttp%3A%2F%2Fi.img - gtht90

2

固定宽度

$message = @iconv("UTF-8","Windows-1252//IGNORE",$message);  

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接