从一个 PHP 页面,我试图将一些数据发布到另一个 PHP 页面并取回数据。
这是我目前拥有的:
<?php
// Initialize cURL session
$ch = curl_init('postpage.php');
// Set some options on the session
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('field1' => 'Andrew'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute post
$result = curl_exec($ch);
var_dump($result);
// Close the session
curl_close($ch);
?>
在 postpage.php 中:
<?php
echo 'Receipt of post request. field1:'.$_POST["field1"];
?>
所有 var_dump 给我的是:
string(0) ""
为什么我收不到短信?
谢谢!
最佳答案
从您的 php 脚本执行的 curl 不知道当前环境,也就是说,您不能使用相对 url。您提供给 curl_init 的 url 必须是绝对的(即包括 http://)
关于php - 使用 PHP 发布并获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9518930/