您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

关于file_get_contents获取借口403

2024/3/2 9:40:00发布14次查看
rt.
有一个接口,本身是302过的
curl -l api location -----> 正确返回数据(预期)curl api location -----> 返回空(预期)curl -i api location ------> 头提示302(预期)

如此上面的结论看出,接口是按照预期的想法输出的
由于项目架构的调整,所以才有上面302的产生,但是
php cli方式
var_dump(file_get_contents('api loaction'))-->返回空(非预期)

最后参考stackoverflow:
stackoverflow 1
stackoverflow 2
ini_set('user_agent','mozilla/4.0 (compatible; msie 6.0)'); var_dump(file_get_contents('api loaction'))-->返回预期数据(预期)

stackoverflow上的解释:
this is not a problem with your script, but with the resource you are requesting. the web server is returning the forbidden status code.
it could be that it blocks php scripts to prevent scraping, or your ip if you have made too many requests.
you should probably talk to the administrator of the remote server.
最后问题来了:
既然server端做了处理,那么curl和file_get_contents 是怎么的差异导致结果不一样?
回复内容: rt.
有一个接口,本身是302过的
curl -l api location -----> 正确返回数据(预期)curl api location -----> 返回空(预期)curl -i api location ------> 头提示302(预期)

如此上面的结论看出,接口是按照预期的想法输出的
由于项目架构的调整,所以才有上面302的产生,但是
php cli方式
var_dump(file_get_contents('api loaction'))-->返回空(非预期)

最后参考stackoverflow:
stackoverflow 1
stackoverflow 2
ini_set('user_agent','mozilla/4.0 (compatible; msie 6.0)'); var_dump(file_get_contents('api loaction'))-->返回预期数据(预期)

stackoverflow上的解释:
this is not a problem with your script, but with the resource you are requesting. the web server is returning the forbidden status code.
it could be that it blocks php scripts to prevent scraping, or your ip if you have made too many requests.
you should probably talk to the administrator of the remote server.
最后问题来了:
既然server端做了处理,那么curl和file_get_contents 是怎么的差异导致结果不一样?
这里是不是没说清楚?op这里 file_get_contents 的时候也是返回403吗?
如果仅仅是按照下面改ua来说,似乎只是这里影响了。
curl 与 file_get_contents 的差异,如果不看源代码的比较方法,应该是使用 tcpdump 等命令去抓一下发出去的请求内容,再做比较。
# tcpdump -i eth0 -a -n -v port ...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product