I need to send a POST request from PHP to a remote HTTPS address, which returns a JSON.
I've used the following code:
//$url = ...
$data = array('username' => $username, 'password' => $passwort);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
However at the last line the function fails with a failed to open stream: HTTP request failed! HTTP/1.1 403 FORBIDDEN
error.
The server also sends an explanation in HTML format, but I have no idea how to access it through file_get_contents
. Help?
EDIT: I will use cURL instead.