【发布时间】:2015-05-13 15:32:48
【问题描述】:
我有一个必须在另一个域上调用 PHP 的 HTML 页面。大多数浏览器的“同源规则”禁止该调用。所以我想在我的域上调用一个 PHP 来调用目标域上的一个 PHP。我想避免使用 cURL,所以我决定在使用 $context 的传递 PHP 中使用 fopen:
$params = array('http' => array('method'=>'POST',
'header'=>'Content-type: application/json',
'content'=>json_encode($_POST)));
$ctx = stream_context_create($params);
$fp = fopen('https://other_domain.com/test.php', 'rb', false, $ctx);
$response = stream_get_contents($fp);
echo $response;
但是 test.php 中传入的$_POST 似乎是空的。有任何想法吗?
【问题讨论】: