File_get_contents excuses 403

Source: Internet
Author: User
Tags php cli
RT. there is an interface, which itself is over 302 {code ...} the above conclusion shows that the interface is output according to the expected idea because of the adjustment of the Project architecture, so the above 302 is generated, but the phpcli method {code ...} finally, refer to stackoverflow: stackoverflow1s... RT.
There is an interface, which is over 302.

Curl-L "api location" -----> return data correctly (expected) curl "api location" -----> return NULL (expected) curl-I "api location" ------> header 302 (expected)

The above conclusion shows that the interface is output according to the expected ideas.

Because of the adjustment of the Project architecture, the above 302 results were generated,

Php cli

Var_dump (file_get_contents ('api loaction') --> return NULL (unexpected)

Finally, refer to stackoverflow:

Stackoverflow 1

Stackoverflow 2

Ini_set ('user _ agent', 'mozilla/4.0 (compatible; MSIE 6.0) '); var_dump (file_get_contents ('api loaction') --> return expected data (expected)

Stackoverflow explanation:

This is not a problem with your script, but with the resource you are requesting. The web server is returning the "forbidden" status code.

It cocould be that it blocks PHP scripts to prevent scraping, or your IP if you have made too required requests.

You shoshould probably talk to the administrator of the remote server.

The last question is:

Since the server has done the processing, how does the difference between curl and file_get_contents lead to different results?

Reply content:

RT.
There is an interface, which is over 302.

Curl-L "api location" -----> return data correctly (expected) curl "api location" -----> return NULL (expected) curl-I "api location" ------> header 302 (expected)

The above conclusion shows that the interface is output according to the expected ideas.

Because of the adjustment of the Project architecture, the above 302 results were generated,

Php cli

Var_dump (file_get_contents ('api loaction') --> return NULL (unexpected)

Finally, refer to stackoverflow:

Stackoverflow 1

Stackoverflow 2

Ini_set ('user _ agent', 'mozilla/4.0 (compatible; MSIE 6.0) '); var_dump (file_get_contents ('api loaction') --> return expected data (expected)

Stackoverflow explanation:

This is not a problem with your script, but with the resource you are requesting. The web server is returning the "forbidden" status code.

It cocould be that it blocks PHP scripts to prevent scraping, or your IP if you have made too required requests.

You shoshould probably talk to the administrator of the remote server.

The last question is:

Since the server has done the processing, how does the difference between curl and file_get_contents lead to different results?

Didn't I make it clear here? OP herefile_get_contentsIs 403 returned when?

If you just change UA as follows, it seems that it is only affected here.

curlAndfile_get_contentsIf you do not look at the source code comparison method, you should usetcpdumpWait for the command to capture the content of the sent request and make a comparison.

# tcpdump -i eth0 -A -n -v port ...

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.