本篇內(nèi)容介紹了“php curl301跳轉(zhuǎn)如何處理”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
專(zhuān)業(yè)成都網(wǎng)站建設(shè)公司,做排名好的好網(wǎng)站,排在同行前面,為您帶來(lái)客戶(hù)和效益!創(chuàng)新互聯(lián)為您提供成都網(wǎng)站建設(shè),五站合一網(wǎng)站設(shè)計(jì)制作,服務(wù)好的網(wǎng)站設(shè)計(jì)公司,成都網(wǎng)站制作、網(wǎng)站建設(shè)負(fù)責(zé)任的成都網(wǎng)站制作公司!
php curl 301跳轉(zhuǎn)的處理方法:1、打開(kāi)相應(yīng)的php文件;2、通過(guò)添加代碼為“curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);”處理301跳轉(zhuǎn)即可。
curl 301 處理
我在處理某個(gè)接口調(diào)用時(shí)發(fā)現(xiàn)postman能正常響應(yīng)數(shù)據(jù),但是程序運(yùn)行時(shí)卻獲取不到正常數(shù)據(jù)響應(yīng).
排查日志發(fā)現(xiàn)代碼里curl時(shí)會(huì)返回301, 所以會(huì)導(dǎo)致接口未能正確獲取到響應(yīng)數(shù)據(jù).
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 處理了 301 跳轉(zhuǎn).
php curl里如果要處理301 跳轉(zhuǎn)的問(wèn)題,需要加上 下面這行代碼:
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
“php curl301跳轉(zhuǎn)如何處理”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
本文標(biāo)題:phpcurl301跳轉(zhuǎn)如何處理
當(dāng)前路徑:http://aaarwkj.com/article8/igciip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、Google、建站公司、響應(yīng)式網(wǎng)站、網(wǎng)站策劃、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)