本文介绍了使用curl将数据发布到安全页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向BarnesAndNoble网站发布pin和数量的giftcard,以获得可用余额。 (我们是从人们购买礼品卡的公司,我们需要验证余额)

I'm trying to post pin and number of giftcard to BarnesAndNoble site to get the available balance. (we are a company buying gift cards from people, and we need to verify the balance)

奇怪的是, ,返回的内容是原始页面(不是结果页面,应该显示输入的PIN码无效,或应该返回金额)

The weird thing is that, the content returned is the original page (not the resulted page where it should say the pin&number entered are invalid, or should return an amount)

我不知道为什么不工作,代码很简单

I wonder why it doesn't work, the code is pretty straight forward

    $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);;


推荐答案

回答我自己的问题:

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

Long answer: read the above linkShort answer: pass the query string into CURLOPT_POSTFIELDS instead of an array (I used array in the above $post)

这篇关于使用curl将数据发布到安全页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:39
查看更多