從PHP頁面,我試圖將一些數據發佈到另一個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) ""
爲什麼我沒有讓文本回來?
謝謝!
這是你正在使用的* actual *'curl_init()嗎?如果是這樣,您需要使用完全限定的URL(協議,主機名,URI)。 – 2012-03-01 15:30:34