如何使用cURL将$ _POST值传递给URL?

时间:2016-12-07 15:16:29

标签: php forms curl post

所以我有这个表格,我想发布到“postUrl”。基本上,当我发布时,我的页面加载到“postUrl”页面。这适用于表单。

问题,可以通过Curl实现同样的目标吗?我有以下两个示例代码。但是,卷曲器无法加载到下一页。我犯了一个错误?

                $live = 0;
                $oid = "1";
                $inv = "1";
                $amount = 10000;
                $tel = "25472#";
                $eml = "#";
                $crl = 2;
                $p1 = "p1";
                $p2 = "p2";
                $p3 = "p3";
                $p4 = "p4";
                $cbk = "#";
                $cst = 1;
                $lbk = "#";
                $curr = "KES";
                $vid = "demo";

Form code

<form method="post" action="https://www.postUrl">
live<input     name="live"  type="hidden" value="<?php echo $live; ?>">
oid<input      name="oid"   type="hidden" value="<?php echo $oid; ?>">
inv<input      name="inv"   type="hidden" value="<?php echo $inv; ?>">
amount<input   name="ttl"   type="hidden" value="<?php echo $amount; ?>">
tel<input      name="tel"   type="hidden" value="<?php echo $tel; ?>">
eml<input      name="eml"   type="hidden" value="<?php echo $eml; ?>">
vid<input      name="vid"   type="hidden" value="<?php echo $vid; ?>">
curr<input     name="curr"  type="hidden" value="<?php echo $curr; ?>">
p1<input      name="p1"     type="hidden" value="<?php echo $p1; ?>">
p2<input      name="p2"     type="hidden" value="<?php echo $p2; ?>">
p3<input      name="p3"     type="hidden" value="<?php echo $p3; ?>">
p4<input      name="p4"     type="hidden" value="<?php echo $p4; ?>">
cst<input     name="cst"    type="hidden" value="<?php echo $cst; ?>">
lbk:<input    name="lbk"    type="hidden" value="<?php echo $cbk; ?>" >
cbk<input     name="cbk"    type="hidden" value="<?php echo $cbk; ?>">
crl:<input    name="crl"    type="hidden" value="<?php echo $crl; ?>" >
hash<input    name="hsh"    type="hidden" value="<?php echo $generated_hash; ?>">
  <button type="submit" class="btn btn-primary pull-right">Submit</button>
</form>

Curl code

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://www.ipayafrica.com/payments/v3/ke");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 
    http_build_query(array(
                    'live' => $live,
                    'oid' => $oid,
                    'inv' => $inv,
                    'ttl' => $amount,
                    'tel' => $tel,
                    'eml' => $eml,
                    'vid' => $vid,
                    'curr' => $curr,
                    'p1' => $p1,
                    'p2' => $p2,
                    'p3' => $p3,
                    'p4' => $p4,
                    'cst' => $cst,
                    'lbk' => $lbk,
                    'cbk' => $cbk,
                    'crl' => $crl,
                    'hsh' => $generated_hash)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

我不知道为什么Curl选项加载失败。有谁带我?

0 个答案:

没有答案