我有这样的链接,
https://www.example.com/enter_check/=/declared=yes/?url=https%3A%2F%2Fwww.example.com%2Fitem_detail当您通过浏览器访问时。
它跳转到https://www.example.com/item_detail
然而,我在PHP上使用file_get_contents访问,它不会跳转,甚至当我假装浏览器是用户代理时,仍然不能工作。
$context = stream_context_create(array('http' => array(
'method' => 'GET',
'header' => 'User-Agent: Mozilla/6.4 (compatible; MSIE 4.0; Windows 98; DigExt)',
)));
$source = file_get_contents($url,false,$context);有什么想法吗?这是否可能使file_get_contents以与浏览器相同的方式工作?
发布于 2020-07-22 20:16:15
我想你需要在你的上下文中添加follow_location选项:
$context = stream_context_create(array('http' => array(
'method' => 'GET',
'header' => 'User-Agent: Mozilla/6.4 (compatible; MSIE 4.0; Windows 98; DigExt)',
'follow_location' => true,
)));
$source = file_get_contents($url,false,$context);https://stackoverflow.com/questions/63033826
复制相似问题