php fopen:无法打开流:HTTP 请求失败! HTTP/1.0 403

问题描述 投票:0回答:3

当我尝试打开其他网站的文件时,我在 PHP 5 中收到错误消息。所以这条线

fopen("http://www.domain.com/somef­ile.php", r)

返回错误

警告:fopen(www.domain.com/somefile.php) [function.fopen]:无法打开流:HTTP 请求失败! HTTP/1.1 403 Forbidden in D:\xampp\htdocs\destroyfiles\index.php 第 2 行

file-io php
3个回答
1
投票

您的 PHP 应用程序无法进行身份验证。请求 URI 应该是:

http://user:[email protected]/somefile.php

0
投票

看起来您的 PHP 客户端(即运行 PHP 脚本的服务器)不允许通过

http://www.domain.com/somef­ile.php
上的服务器获取
www.domain.com


0
投票

我遇到了类似的问题,使用curl 访问效果很好。但是使用 php 和 fopen,我得到了 http 403

192.168.1.144 - "GET /dop007.pdf HTTP/1.0" 403 392 "-" "-"
192.168.1.144 - "GET /dop007.pdf HTTP/1.1" 302 430 "-" "curl/7.58.0"

我可以通过将 HTTP 版本更改为 1.1 来解决该问题

$context = stream_context_create([
        'http'=>[
                'protocol_version' => 1.1
        ]
]);

if ($file = fopen($filePath, 'rb',false,$context)) {
    while ( ! feof($file) and (connection_status() == 0)) {
        print(fread($file, 1024 * 8));
        flush();
    }
    fclose($file);
} else {
    Log::error('Search Request Failed');
}                
© www.soinside.com 2019 - 2024. All rights reserved.