gpt4 book ai didi

PHP GET 请求,发送 header

转载 作者:IT王子 更新时间:2023-10-28 23:56:31 30 4
gpt4 key购买 nike

我需要执行一个获取请求并发送 header 。我可以用什么来做到这一点?

我需要设置的主要 header 是浏览器 header 。有没有简单的方法可以做到这一点?

最佳答案

如果您使用 cURL,您可以使用 curl_setopt ($handle, CURLOPT_USERAGENT, 'browser description') 来定义请求的用户代理 header 。

如果您使用 file_get_contents,请查看 file_get_contents 手册页上的示例调整:

// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" .
"User-agent: BROWSER-DESCRIPTION-HERE\r\n"
)
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);

关于PHP GET 请求,发送 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3032643/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com