【发布时间】:2014-01-21 07:22:30
【问题描述】:
我正在尝试使用 curl 将一些值发布到 URL
//set up a connection variable for the page you will post data to
$curl_connection = curl_init('https://payment.teqwerty.com/NetBanking/Pay.jsp?');
//curl basic setup
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($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//$_POST variables to pass
$post_items[] = 'MerchantId='.strip_tags($merchantId);
$post_items[] = 'Password='.strip_tags($Password);
$post_items[] = 'RemoteIP='.strip_tags($RemoteIP);
$post_items[] = 'Amount='.strip_tags($Amount);
$post_items[] = 'BankId='.strip_tags($BankId);
$post_items[] = 'Checksum='.strip_tags($checksum);
$post_items[] = 'Name='.strip_tags($Name);
$post_items[] = 'mobileNo='.strip_tags($mobileNo);
$post_items[] = 'Email='.strip_tags($Email);
//format the $post_items into a string
$post_string = implode ('&', $post_items);
//send the $_POST data to the new page
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
curl_close($curl_connection);
我是 curl 的新手,这段代码是我从谷歌搜索的。但这似乎不起作用。但我有一个工作代码
$parameters='MerchantId='.$merchantId.'&Password='.$Password.'&ReferenceNo='.$ReferenceNo.'&RemoteIP='.$RemoteIP.'&Amount='.$Amount.'&BankId='.$BankId.'&Checksum='.$checksum.'&Name='.$Name.'&MobileNo='.$MobileNo.'&Email='.$Email;
//echo "para is <br>".$parameters;
//set POST variables
$url = 'https://payment.teqwerty.com/NetBanking/Pay.jsp?'.$parameters;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$auth = curl_exec($curl);
以上工作正常。但奇怪的是,有时这会卡住并且不起作用。我想将参数发布到该 URL。无论如何,我不会得到任何变量作为回报。为什么第一个代码不起作用。我做错了吗?
【问题讨论】:
-
尝试发布 url "payment.teqwerty.com/NetBanking/Pay.jsp" 然后 $postfields 和 curl_setopt($curl_connection, CURLOPT_POST,1);
-
当第二种方法有效时为什么不使用它?
-
@ShankarDamodaran 它正在工作,但有时会卡住。我无法弄清楚原因。有时它工作正常