开发者

How do I change the headers that PHP sends when using file_get_contents on an external URL?

I need to change the headers that PHP sends when it requests a file using file_get_contents(). Is that possible or would I have to use CUR开发者_开发问答L?


You can use file_get_contents() in conjunction with stream_context_create()

Exemple :

<?php
$context = stream_context_create(array(
    'http'=>array(
        'method'=>"GET",
        'header'=>"Accept-language: en\r\n" .
                  "Cookie: foo=bar\r\n"
  )
));
$out = file_get_contents($filename, false, $context);


You will need to use CURL. It's also more reliable. See curl_setopt and CURLOPT_HTTPHEADER.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜