我正在使用具有基本身份验证的file_get_contents调用rest api。该请求在Postman中工作正常,但使用file_get_contents响应404。
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json\r\nAuthorization: Basic " . base64_encode('username:password') . "\r\n",
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);