使用curl发布数据时,IE和Chrome会删除空格

时间:2011-07-20 04:52:34

标签: php curl

$first1 = $_POST['CFirst'];
$last1 = $_POST['CLast'];
$Phone1 =$_POST['Phone'];
$Fax1 =  $_POST['Fax'];
$CEmail1 = $_POST['CEmail'];
$message1 = $_POST['Message']

$post_string = "ID=$id&Source=$Source&noMail=$noMail&CFirst=$first1&CLast=$last1&Phone=$Phone1&CEmail=$CEmail1&Message=$message1";

//create cURL connection
$curl_connection = 
  curl_init($url);

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, 
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

上面代码的问题在于它删除了chrome和IE中的空格,但是在Firefox的情况下它工作正常。 例如:- 让我们说如果我在输入字段中放置空格'你好,你好吗'。现在它就像IE / chrome一样以Hellohowareyou的形式出现。可能是什么问题?

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我不确定这是否有帮助,但只是分享我编写的函数以使用curl获取页面。

function get_web_page($url)
    {
            //echo "curl:url<pre>".$url."</pre><BR>";
        $options = array(
            CURLOPT_RETURNTRANSFER => true,     // return web page
            CURLOPT_HEADER         => false,    // don't return headers
            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_USERAGENT      => "spider", // who am i
            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
            CURLOPT_CONNECTTIMEOUT => 15,      // timeout on connect
            CURLOPT_TIMEOUT        => 15,      // timeout on response
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects

        );

        $ch      = curl_init($url);
        curl_setopt_array( $ch, $options );
        $content = curl_exec( $ch );
        $err     = curl_errno( $ch );
        $errmsg  = curl_error( $ch );
        $header  = curl_getinfo( $ch,CURLINFO_EFFECTIVE_URL );
        curl_close( $ch );

        $header['errno']   = $err;
        $header['errmsg']  = $errmsg;

        //change errmsg here to errno
        if ($errmsg)
        {
            echo "CURL:".$errmsg."<BR>";
        }
        return $content;
    }