开发者

IE and Chrome remove spaces when post data using 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(开发者_如何学C$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);

The problem with the above code is that it removes spaces in chrome and IE but in case of Firefox its working fine. e.g:- Lets says if i put spaces in my input field 'Hello how are you'. now right now its going as Hellohowareyou in case of IE/chrome. What can be the problem?

Any ideas?


I am not sure if this helps, but just sharing a function I have written to get pages using 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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜