How does phpfile_get_content obtain the error message?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.