没有网络表单的PHP POST数据 [英] PHP POST data without web form
本文介绍了没有网络表单的PHP POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种无需使用Web表单即可发送POST数据的方法?我正在与第三方付款处理器合作,可以选择手动提交付款,但数据必须采用POST格式.
Is there a way to send POST data without using a web form? I am working with a 3rd party payment processor and I have an option to manually submit payment but the data is required to be POST formatted.
我计划将脚本作为CRON作业运行,因此它是自动化的,因此不需要用户通过Web表单提交输入.
I plan to run my script as CRON job and so as it is automated there is no user input via a web form submission.
谢谢.
推荐答案
尝试CURL
http://php.net/manual/en/book.curl.php >
//set POST variables
$url = 'http://domain.com/get-post.php';
$fields = array(
'lname' => urlencode($last_name),
'fname' => urlencode($first_name),
'title' => urlencode($title),
'company' => urlencode($institution),
'age' => urlencode($age),
'email' => urlencode($email),
'phone' => urlencode($phone)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
这篇关于没有网络表单的PHP POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文