(資料圖片)
本教程操作環境:Windows10系統、PHP8.1版、DELL G3電腦
php curl 301跳轉怎么處理?
curl 301 處理
我在處理某個接口調用時發現postman能正常響應數據,但是程序運行時卻獲取不到正常數據響應.
排查日志發現代碼里curl時會返回301, 所以會導致接口未能正確獲取到響應數據.
curl -i http://www.example.com/fetchAvailability\?startDate\=2021-02-08\&endDate\=2021-02-08\&startTime\=00%3A00%3A00\&endTime\=23%3A59%3A59HTTP/1.1 301 Moved PermanentlyDate: Tue, 09 Feb 2021 00:39:19 GMTOT-RequestId: 74eadfc7-50a1-4610-83ab-4beab3581621X-Content-Type-Options: nosniffX-XSS-Protection: 1; mode=blockSet-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=NoneSet-Cookie: OT-Session-Update-Date=1612831159; Path=/; Domain=example.com; Expires=Tue, 09-Feb-2021 01:09:19 GMT; Max-Age=1800; Secure; SameSite=NoneLocation: https://www.example.com/FetchAvailability?startDate=2021-02-08&endDate=2021-02-08&startTime=00%3A00%3A00&endTime=23%3A59%3A59Content-Length: 0
postman 處理了 301 跳轉.
php curl里如果要處理301 跳轉的問題,需要加上 下面這行代碼:
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
推薦學習:《PHP視頻教程》
以上就是php curl 301跳轉怎么處理的詳細內容,更多請關注php中文網其它相關文章!
關鍵詞: curl