Actually I want to read the contents that come after the search query, when it is done. The problem is that the URL only accepts POST
methods, and it does not t
Another alternative of the curl-less method above is to use the native stream functions:
Creates and returns a stream context with any options supplied in options preset.
Identical to file_get_contents(), except that
stream_get_contents()
operates on an already open stream resource and returns the remaining contents in a string, up to maxlength bytes and starting at the specified offset.
A POST function with these can simply be like this:
[
'header' => [ // header array does not need '\r\n'
'Content-type: application/x-www-form-urlencoded',
'Content-Length: ' . strlen($query_content)
],
'method' => 'POST',
'content' => $query_content
]
]));
if ($fp === FALSE) {
return json_encode(['error' => 'Failed to get contents...']);
}
$result = stream_get_contents($fp); // no maxlength/offset
fclose($fp);
return $result;
}