php curl 301 jump processing method: 1. Open the corresponding php file; 2. Process the 301 jump by adding the code "curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);".
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
How to deal with php curl 301 jump ?
curl 301 processing
When I was processing an interface call, I found that postman could respond to data normally, but the normal data response could not be obtained when the program was running.
Check the log and find that curl in the code will return 301, which will cause the interface to fail to obtain the response data correctly.
curl -i http://www.example.com/fetchAvailability\?startDate\=2021-02-08\&endDate\=2021-02-08\&startTime\=00%3A00%3A00\&endTime\=23%3A59%3A59 HTTP/1.1 301 Moved Permanently Date: Tue, 09 Feb 2021 00:39:19 GMT OT-RequestId: 74eadfc7-50a1-4610-83ab-4beab3581621 X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Set-Cookie: OT-SessionId=b1db19cb-00cf-47be-95ac-33eee1172706; Path=/; Domain=example.com; Expires=Tue, 09-Feb-2021 01:09:19 GMT; Max-Age=1800; Secure; SameSite=None Set-Cookie: OT-Session-Update-Date=1612831159; Path=/; Domain=example.com; Expires=Tue, 09-Feb-2021 01:09:19 GMT; Max-Age=1800; Secure; SameSite=None Location: https://www.example.com/FetchAvailability?startDate=2021-02-08&endDate=2021-02-08&startTime=00%3A00%3A00&endTime=23%3A59%3A59 Content-Length: 0
postman handles the 301 jump.
If you want to handle it in curl For 301 jump issues, you need to add the following line of code:
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to handle php curl 301 jump. For more information, please follow other related articles on the PHP Chinese website!