您的位置:首页 > 技术中心 > PHP教程 >

php curl 301跳转怎么处理

时间:2023-02-03 11:07

php curl 301跳转的处理方法:1、打开相应的php文件;2、通过添加代码为“curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);”处理301跳转即可。

本教程操作环境: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%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 跳转.

php curl里如果要处理301 跳转的问题,需要加上 下面这行代码:

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

推荐学习:《PHP视频教程》

以上就是php curl 301跳转怎么处理的详细内容,更多请关注gxlsystem.com其它相关文章!

本类排行

今日推荐

热门手游