When php is used as a cross-origin proxy and the file_get_content function is used to send a get request, the opposite server sets that if a verification error occurs, http422 is triggered, and a json value is returned. Could you tell me how to get this json value, because the function directly returns the link creation failure ,... when php is used as a cross-origin proxy and the file_get_content function is used to send a get request, the opposite server sets that if a verification error occurs, http 422 is triggered and a json value is returned.
How can I obtain this json value because the function returns a link creation failure without any value.
Reply content:
When php is used as a cross-origin proxy and the file_get_content function is used to send a get request, the opposite server sets that if a verification error occurs, http 422 is triggered and a json value is returned.
How can I obtain this json value because the function returns a link creation failure without any value.
Reference (ladder may be required)
set_error_handler( create_function( '$severity, $message, $file, $line', 'throw new ErrorException($message, $severity, $severity, $file, $line);' ));try { file_get_contents('www.google.com');}catch (Exception $e) { echo $e->getMessage();}restore_error_handler();
Curl is also recommended.
You have a website. Can you test it?
Returns false? Try accessing Baidu or anything.
This application scenario does not seem to have been met yet. Why should we return 422? If there is a return value, it should be 200. Then we can judge the json format and try curl.
This function doesn't work. You can use the curl Series Function to try it.
function get_contents(){ $content = @file_get_contents("http://segmentfault.com/q/101000000427840111"); var_dump($http_response_header); var_dump($content);}get_contents();
The returned http status code can be obtained in this way.
However, if the returned value is not 200, file_get_contents returns false.
Different http status codes can be judged for different logic processing.