使用curl发布数据以保护页面

时间:2012-02-16 08:48:39

标签: php curl

我正在尝试将礼品卡的针数和数量发布到BarnesAndNoble网站以获得可用余额。 (我们是一家从人们那里购买礼品卡的公司,我们需要验证余额)

https://cart2.barnesandnoble.com/gc/gc_ViewBalance.asp

奇怪的是,返回的内容是原始页面(不是结果页面,它应该说输入的&数字无效,或者应该返回金额)

我想知道为什么它不起作用,代码很简单

    $ch = curl_init();
    $formUrl = 'https://cart2.barnesandnoble.com/gc/gc_ViewBalance.asp ';
    $ckfile = __DIR__.'\cookie.txt';



    curl_setopt($ch, CURLOPT_URL, $formUrl);        
    curl_setopt($ch, CURLOPT_REFERER, $formUrl);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);   

    $urldata = parse_url($formUrl); 
    $headers = array("Host: ".$urldata['host']);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

    // tried this as well 
    //curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/GTECyberTrustGlobalRoot.crt");

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);


    //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return content as a string
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);


    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $content = curl_exec($ch);;

1 个答案:

答案 0 :(得分:0)

回答我自己的问题:

PHP curl resets content-length if CURLOPT_POST is set with curl_setopt_array?

答案很长:阅读上面的链接 简答:将查询字符串传递给CURLOPT_POSTFIELDS而不是数组(我在上面的$ post中使用了数组)