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_contents
Is 403 returned when?
If you just change UA as follows, it seems that it is only affected here.
curl
Andfile_get_contents
If you do not look at the source code comparison method, you should usetcpdump
Wait for the command to capture the content of the sent request and make a comparison.
# tcpdump -i eth0 -A -n -v port ...