服务器之家

服务器之家 > 正文

PHP使用file_get_content设置头信息的方法

时间:2020-12-21 15:04     来源/作者:思齐_

本文实例讲述了PHP使用file_get_content设置头信息的方法。分享给大家供大家参考,具体如下:

直接上代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
Accept application/json
Accept-Encoding gzip, deflate
Accept-Language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Connection keep-alive
Cookie mzys_is_frist_access=1; mzys_c_uuid=guest_215cbc0979b5bd2; mzys_access20130610=1; mzys_qz_uuid=d6d4640f93cb7a4; CNZZDATA30040410=cnzz_eid%3D1008690174-1370849811-http%253A%252F%252Fm.120ask.com%26ntime%3D1370855345%26cnzz_a%3D43%26retime%3D1370855484258%26sin%3D%26ltime%3D1370855484258%26rtime%3D0; PHPSESSID=4kacoqfe4ae33km3h0l2imjfd6
Host m.120ask.com
Referer http://m.120ask.com/health/show?page=2&id=84882&type=17
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0
X-Requested-With XMLHttpRequest
 */
$hdrs = array(
  'http' =>array('header' =>
   "Accept: application/json\r\n" .
   "Accept-Encoding: gzip, deflate\r\n" .
   "Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3\r\n" .
   "Accept-Encoding: gzip, deflate\r\n" .
   "Connection: keep-alive\r\n" .
   "Cookie: mzys_is_frist_access=1; mzys_c_uuid=guest_215cbc0979b5bd2; mzys_access20130610=1; mzys_qz_uuid=d6d4640f93cb7a4; CNZZDATA30040410=cnzz_eid%3D1008690174-1370849811-http%253A%252F%252Fm.120ask.com%26ntime%3D1370855345%26cnzz_a%3D43%26retime%3D1370855484258%26sin%3D%26ltime%3D1370855484258%26rtime%3D0; PHPSESSID=4kacoqfe4ae33km3h0l2imjfd6\r\n" .
   "Host: m.120ask.com\r\n" .
   "Referer: http://m.120ask.com/health/show?page=2&id=84882&type=17\r\n" .
   "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0\r\n" .
   "X-Requested-With: XMLHttpRequest",
   'timeout'=>2
  ),
);
$context = stream_context_create($hdrs);
//方式1
// $fp = fopen("http://m.120ask.com/health/show?page=2&id=84882&type=17", 'r', false, $context);
// fpassthru($fp);
// fclose($fp);
//方式2
//echo file_get_contents('http://m.120ask.com/health/show?page=2&id=84882&type=17', 0, $context);

希望本文所述对大家PHP程序设计有所帮助。

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址 2020-08-12
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
返回顶部