file_get_contents 获取不了网页内容
服务器在做验签的过程中,经常需要向渠道服务器获取某个用户的信息。一般有两种方法,curl和file_get_contents。
一般情况下,像这样用,不会有问题。
public function OauthPostExecuteNew($sign,$requestString,$request_serverUrl){
$opt = array("http"=>array(
"method"=>"GET",
"header"=>array("param:".$requestString,"oauthsignature:".$sign),
"request_fulluri"=>true
)
);
$context = stream_context_create($opt);
$res=file_get_contents($request_serverUrl, false, $context);
return $res;
}
但是由于我司服务器连外网时通过代理,所以在使用stream_context_create时需要带上proxy参数,才能访问到渠道的服务器。
所以在上面代码 $opt 数组中带上"proxy"=>$proxy字段。加上之后发现file_get_contents仍然不能正常验签。
百思不解,遂到官网上来查查file_get_contents,发现并没有关于proxy的解释,然后搜stream_context_create,官方解释有这句话
params必须是 $arr['parameter'] = $value 格式的关联数组。 请参考 context parameters 里的标准资源流参数列表。
那么 我们进入context_parameters 查看参数配置。因为我们使用的是HTTP方式,所以查看HTTP context
查看跟proxy相关的
proxystringURI 指定的代理服务器的地址。(e.g. tcp://proxy.example.com:5100).
request_fulluriboolean当设置为
TRUE时,在构建请求时将使用整个 URI 。(i.e. GET http://www.example.com/path/to/file.html HTTP/1.0)。 虽然这是一个非标准的请求格式,但某些代理服务器需要它。默认值是
FALSE.
发现只配置了proxy,而并没有配置request_fulluri,遂加上request_fulluri=true,验证通过。
注意:使用proxy参数时需要把http 改为tcp 具体什么原因,不知道。等我查到了再到这里更新。
file_get_contents 获取不了网页内容的更多相关文章
- curl 或 file_get_contents 获取需要授权页面的方法
原文:http://blog.csdn.net/fdipzone/article/details/44475801 红色字体部分是加上自己的注释,整理了一下. 今天因工作需要,需要用 curl / f ...
- file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did
file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did 解决办法 ,如果你是用的服务器,可以参考这个办法,修改 ...
- 解析PHP中的file_get_contents获取远程页面乱码的问题【转】
在工作中,遇到一个问题.我需要将一个网址(该网址是一个json数据的接口,即 打开该网址,在浏览器中显示的是json数据),我使用file_get_contents($url),数据是乱码的. 通过查 ...
- PHP CURL或file_get_contents获取网页标题的代码及两者效率的稳定性问题
PHP CURL与file_get_contents函数都可以获取远程服务器上的文件保存到本地,但在性能上面两者完全不在同一个级别,下面我先来介绍PHP CURL或file_get_contents函 ...
- PHP下通过file_get_contents\curl的方法实现获取远程网页内容(别忘了还有PhpRPC)
[php]PHP中file_get_contents()与file_put_contents()函数细节详解 php函数file_get_contents(一) 案例: 早在2010年时候遇到过这样的 ...
- file_get_contents无法获取数据的一种情况
下面这段php代码突然不好使了,返回的 $html 为空,百思不得解.网上说法好多,但都是一家之言,解决不了我的问题.(我的解决方法也是一家之言,只能解决file_get_contents获取不到数据 ...
- file_get_contents函数获取不到数据的一种情况
问题: file_get_contents($url) 获取不到数据,尽管URL地址正确,函数使用正确.如下代码 $url = "https://www.baidu.com"; ...
- PHP-CGI 进程 CPU 100% 与 file_get_contents 函数的关系
[文章作者:张宴 本文版本:v1.0 最后修改:2011.08.05 转载请注明原文链接:http://blog.s135.com/file_get_contents/] 有时候,运行 Nginx.P ...
- php fopen()和file_get_contents() 区别介绍
本文章向码农们介绍PHP使用fopen与file_get_contents读取文件实例分享及这两个函数的区别,需要的码农可以参考一下. php中读取文件可以使用fopen和file_get_conte ...
随机推荐
- JS判断请求来自Android手机还是iPhone手机,根据不同的手机跳转到不同的链接。
<script type="text/javascript">var browser = {versions: function () {var u = navigat ...
- [Python 3.x 官方文档翻译]Whetting Your Appetite 欢迎您的使用
If you do much work on computers, eventually you find that there’s some task you’d like to automate. ...
- Codeforces 526E Transmitting Levels
http://codeforces.com/contest/526/problem/E 题意:给一个环,每个点有权值,每次给一个数B,求把这个环切割成若干部分,每个部分不超过B,至少要切成几块? #i ...
- 在O(1) 时间删除链表节点
struct Node { int val; Node * next; }; void deleteNode(Node ** head, Node * target) { assert(head != ...
- CentOs6.5中安装和配置vsftp简明
这篇文章主要介绍了CentOs6.5中安装和配置vsftp简明教程,需要的朋友可以参考下 一.vsftp安装篇 复制代码代码如下: # 安装vsftpdyum -y install vsftp ...
- NSIS如何对一整个目录文件夹(包括子文件夹和其中的文件)压缩
原来不加/r参数,NSIS编译器就会不认识文件夹啊. File /r [dir] Reference: http://stackoverflow.com/questions/7973242/nsis- ...
- Row Cache Objects
This latch comes into play when user processes are attempting to access or update the cached data di ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- bzoj1145
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1145 神题...... 定义f(abcd)为高度排名为abcd的个数,例如闪电的个数为f(13 ...
- Lucene 高亮功能
原文转载自: http://qindongliang1922.iteye.com/blog/1953409 高亮功能一直都是全文检索的一项非常优秀的模块,在一个标准的搜索引擎中,高亮的返回命中结果,几 ...