php file_get_content获取资源时添加header请求头

  • Post author:
  • Post category:php


<?php
    $context_options = array(
        'http' =>
            array(
                'method' => "GET",
                'header' => "User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36\r\nReferer:http://www.zhuyanjun.cn/\r\n",
                'timeout' => 120,
            )
    );

    $context = stream_context_create($context_options);
    $html = file_get_contents('https://www.demo.com/',FALSE,$context);



版权声明:本文为JineD原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。