使用cURL发布数据

时间:2015-02-13 16:04:53

标签: php curl

我想使用cURL发布此表单数据:

<form id="subFrm" name="subFrm" method="post" action="https://www.example.com/Test/test_checksum.php">

        <input type="hidden" name="surl" value='http://www.example.com/surl.php'>
        <input type="hidden" name="furl" value='http://www.example.com/furl.php'>
        <input type="hidden" name="hash" value="<?php echo $hash; ?>">

        <input type="hidden" name="email" value="<?php echo $email; ?>">
        <input type="hidden" name="phone" value="<?php echo $phone; ?>">
        <input type="hidden" name="firstname" value="<?php echo $firstname; ?>">
        <input type="hidden" name="productinfo" value="Product Information">
        <input type="hidden" name="amount" value="<?php echo $amount; ?>">
        <input type="hidden" name="txnid" value="<?php echo $txnid; ?>">
        <input type="hidden" name="key" value="<?php echo $key; ?>"> 
        <input type="hidden" name="service_provider" value="payu_paisa">
        <input type="submit" value="Pay via PayUMoney"/>
      </form>

我写的cURL代码如下:

<?php 

$posted = array();

    $posted['key'] = $key;
    $posted['txnid'] = $txnid;
    $posted['productinfo'] = $productinfo;
    $posted['amount'] = $amount;
    $posted['firstname'] = $firstname;
    $posted['email'] = $email;
    $posted['phone'] = $phone;
    $posted['surl'] = 'http://www.example.com/surl.php' ;
    $posted['furl'] = 'http://www.example.com/furl.php' ;
    $posted['service_provider'] = 'payu_paisa';
    $posted['hash'] = $hash;

    $PAYU_BASE_URL = "https://www.example.com/Test/test_checksum.php";

$post_string = http_build_query($posted) . "\n";


echo $post_string;

$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $PAYU_BASE_URL);
curl_setopt($ch,CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);


?>  

但是,此cURL代码无效。我没有使用cURL的经验。我正在努力找到正确的&#39; curl_setopt()&#39;命令。有人可以帮我弄这个吗?

0 个答案:

没有答案