您好,登錄后才能下訂單哦!
這篇文章給大家介紹如何在PHP中使用file_get_content設置頭信息,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
代碼:
<?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中使用file_get_content設置頭信息就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。