【问题标题】:PHP Curl post with non-english characters带有非英文字符的 PHP Curl 帖子
【发布时间】:2026-01-29 05:25:01
【问题描述】:

我对 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 resimleri, dizi indirme ve altyazı linkine aşağıdan ulaşabilirsiniz.` 

这是它的发布方式:

`Bölüm resimleri, dizi indirme ve altyazı linkine aşağıdan ulaşabilirsiniz.` 

谢谢

【问题讨论】:

  • 垃圾邮件发送者?你是怎么得出这个结论的?只是因为我在一个 php 函数上寻求帮助?

标签: php post curl utf-8


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    来自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"
    ));
    

    @spencercw 建议的application/x-www-form-urlencoded

    【讨论】:

    • 不起作用。我收到“由于缺少安全令牌,无法处理您的提交。”
    • 我猜你需要 application/x-www-form-urlencoded 而不是 text/xml 的内容类型。
    • 您的$post_fields 变量是否包含securitytoken 条目?
    • 与 application/x-www-form-urlencoded “您的提交无法处理,因为缺少安全令牌”,是的,我有一个 securitytaken 变量,我从提交页面使用 curl 获取它
    • 我对此进行了一些环顾,我发现的一个建议是在您的表单发布变量上使用url_encode()。因此,请尝试删除新的 curl_setopt 并在构成 $post_fields 变量的每个字段上使用 url_encode