php curl301跳转如何处理

2023-02-08 22:46:36 5 0
魁首哥

php curl301跳转如何处理

本篇内容介绍了“php curl301跳转如何处理”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

php curl301跳转如何处理

php curl 301跳转的处理方法:1、打开相应的php文件;2、通过添加代码为“curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);”处理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 curl301跳转如何处理”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注恰卡编程网网站,小编将为大家输出更多高质量的实用文章!

收藏
分享
海报
0 条评论
5
上一篇:PHP元转分的错误示范代码分析 下一篇:golang切片长度与容量指的是什么

本站已关闭游客评论,请登录或者注册后再评论吧~

忘记密码?

图形验证码