php file_get_contents中context选项的应用

来源:互联网 发布:mac os root 编辑:程序博客网 时间:2024/05/08 19:30
<pre name="code" class="php">
<?php//以PUT方法为例$url = 'www.baidu.com';$data = array('a' => 'aaaa');$context_options = array (        'http' => array (         'method' => 'PUT',         //如果请求里面需要带验证信息可以将token和其他信息写进一个数组里(这个功能是php 5.2.10开始支持的,原先只支持字符串)          'header'=> Array($token,'Content-type: application/x-www-form-urlencoded'),          'content' => json_encode($data),  'timeout' => 1             ) );$context = stream_context_create($context_options);$fp = file_get_contents($url, false, $context);var_dump($http_response_header);//可以看到返回的头信息?>



0 0