没有 Web 表单的 PHP POST 数据

标签 php forms post web

有没有一种方法可以不使用网络表单来发送 POST 数据?我正在使用第 3 方支付处理器,我可以选择手动提交支付,但数据需要采用 POST 格式。

我计划将我的脚本作为 CRON 作业运行,因为它是自动化的,所以没有用户通过 Web 表单提交输入。

提前致谢。

最佳答案

试试 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);

关于没有 Web 表单的 PHP POST 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19454717/

相关文章:

post - 带有 XMLHttpRequest 的 Https 请求

php - SilverStripe限制3级子页面

javascript - 如何通过选择标签更改占位符?

python - Flask - 不允许使用 POST 错误 405 方法

javascript - 当按钮被禁用时,jQuery 脚本在 safari 中不起作用

database - 为什么已知有效的 Django 模型实例在从数据库检索后 is_valid() 失败?

php - jquery $.post 和 php $_POST

php - 更改 Magento 配置以使用套接字

php - 数据库查询选择两个表,按日期和限制排序

php - 使用简码时将 css 添加到 WordPress