有没有一种方法可以在不使用Web表单的情况下发送POST数据?我正在与第三方付款处理器合作,可以选择手动提交付款,但是数据必须采用POST格式。
我计划将脚本作为CRON作业运行,因此它是自动化的,因此不需要用户通过Web表单提交输入。
预先感谢。
尝试CURL
http://php.net/manual/zh/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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句