我有以下代码可在 PHP5 上使用,以在不使用 cURL 的情况下发送 HTTP POST。我希望这适用于 PHP 4.3.0 及更高版本:
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Type: application/json\r\n",
'content' => $query
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
仅 PHP5 支持 HTTP 上下文。有没有办法让它与 PHP 4.3.0 一起工作 - 如果没有安装 PHP5 或 cURL,我需要一个后备方法。