用PHP发布并获得结果

And*_*eek 2 php post libcurl

从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);
?>
Run Code Online (Sandbox Code Playgroud)

并在postpage.php中:

<?php
echo 'Receipt of post request. field1:'.$_POST["field1"];
?>
Run Code Online (Sandbox Code Playgroud)

所有var_dump给我的是:

string(0) "" 
Run Code Online (Sandbox Code Playgroud)

为什么我没有收回文字?

谢谢!

sci*_*uff 6

从您的php脚本执行的curl不知道当前环境,也就是说,您不能使用相对URL.您提供给curl_init的网址必须是绝对的(即包括http://)