curl_setopt 注意
最近碰到好多奇怪的BUG,今天就是一个例子。
我在用CURL调用麦考林的接口,在浏览器测试完全没问题,调用全都成功。但是用命令行执行PHP时,却一直不行,返回http code 302错误。百思不得其解,后来经理帮忙才找到问题所在。
curl初始化时有这样一行代码:
curl_setopt($ch, CURLOPT_USERAGENT, isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/5.0');
用命令行调用时,跟浏览器测试时的环境是不一样的,这里的 isset($_SERVER['HTTP_USER_AGENT']) 就会是false。有些接口可能时为了某些原因,可能是安全,而阻止你的请求。
以后切记!
curl_setopt 注意的更多相关文章
- PHP CURL CURLOPT参数说明(curl_setopt)
CURLOPT_RETURNTRANSFER 选项: curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 如果成功只将结果返回,不自动输出任何内容. 如果失败返回F ...
- PHP中CURL方法curl_setopt()函数的一些参数
bool curl_setopt (int ch, string option, mixed value)curl_setopt()函数将为一个CURL会话设置选项.option参数是你想要的设置,v ...
- PHP的CURL方法curl_setopt()函数案例介绍(抓取网页,POST数据)
通过curl_setopt()函数可以方便快捷的抓取网页(采集很方便),curl_setopt 是php的一个扩展库 使用条件:需要在php.ini 中配置开启.(PHP 4 >= 4.0.2) ...
- PHP中CURL方法curl_setopt()函数的参数
PHP CURL curl_setopt 参数 bool curl_setopt (int ch, string option, mixed value)curl_setopt()函数将为一个CURL ...
- curl_setopt用此函数设置上传文件请求的兼容性调整
在用curl_setopt($curl, CURLOPT_POSTFIELDS, $fileData);这个函数设置时会报错如下 curl_setopt(): The usage of the @fi ...
- PHP中CURL方法curl_setopt()函数的一些参数 (转)
bool curl_setopt (int ch, string option, mixed value) curl_setopt()函数将为一个CURL会话设置选项.option参数是你想要的设置, ...
- curl_setopt函数相关应用及介绍(转)
一.要想使用curl_setopt 这个函数必须在服务器里边进行编译curl这个组件,怎么安装编译这个组件请具体到google搜索 二.curl_setopt的php帮助文档的解释 bool curl ...
- 关于curl_setopt参数的记录
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE) 其中true输出执行结果,false为不输出 fsockopen与curl_setopt请求的区别之一就是 ...
- curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in
当系统开启safe_mode和 open_basedir,在程序中使用以下语句 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 并且遇到301,302状态 ...
- php curl_setopt的相关设置查询手册
bool curl_setopt (int ch, string option, mixed value) curl_setopt()函数将为一个CURL会话设置选项.option参数是你想要的设置, ...
随机推荐
- Win7 下安装MongoDB
1).下载MongoDBhttp://downloads.mongodb.org/win32/mongodb-win32-i386-2.4.5.zip 下载Windows 32-bit版本并解压缩,程 ...
- 51nod【1196】字符串的数量
超级神题! 有n种字符,若此种字符的编号( \(1\) ~ \(n\)),\(i*2>n\),则他后面可接任意字符.若不是,则他后面接的字符编号至少要是他的两倍. 问长度为m的字符串的个数. 这 ...
- Queue Explorer过期处理
Queue Explorer是收费软件,用一段时间后会显示过期界面无法使用, 我们可以删除注册表 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cogin\Queue ...
- hdu-5818 Joint Stacks(模拟)
题目链接: Joint Stacks Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- highcharts 图例全选按钮方法
$('#uncheckAll').click(function(){ var chart = $('#container').highcharts(); var series = chart.seri ...
- NPM 在MacOSX中的使用技巧
经常看到有人说『为啥npm install 的时候报错,显示EACCESS错误…』,之前大家都是sudo大法解决问题,也没太在意. 至于这个问题是brew安装工具的时候造成的,还是系统修改磁盘权限造成 ...
- ACM学习历程——HDU1331 Function Run Fun(锻炼多维dp的打表)
Description We all love recursion! Don't we? Consider a three-parameter recursive function w( ...
- 【Lintcode】075.Find Peak Element
题目: There is an integer array which has the following features: The numbers in adjacent positions ar ...
- dataguard 常规运维操作
1.standby database 正常的打开与关闭 1.1 针对 physical standby打开:--打开数据库SQL>startup; -- 开启 mgr 进程 SQL>ALT ...
- 【hdu2955】 Robberies 01背包
标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在 ...