流明-file_get_contents给出HTTP_INTERNAL_SERVER_ERROR的错误

在流明中,我的代码在下面以api响应的形式发送文件内容,对于某些文档来说,它工作正常,但是对于某些文档,它给出了HTTP_INTERNAL_SERVER_ERROR的错误

$content = base64_encode(file_get_contents($URL));

Symfony\Component\HttpKernel\Exception\HttpException Object
(
    [statusCode:Symfony\Component\HttpKernel\Exception\HttpException:private] => 500
    [headers:Symfony\Component\HttpKernel\Exception\HttpException:private] => Array
        (
        )

[message:protected] => HTTP_INTERNAL_SERVER_ERROR
[string:Exception:private] => 
[code:protected] => 0
[file:protected] => D:\xampp7.1\htdocs\PROJECT_NAME\app\Exceptions\Handler.php
[line:protected] => 76
[trace:Exception:private] => Array
    ( ...

Is there any solution or required to set php.ini veriable ??

In web error log it gives me error like,

failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version not supported

to resolve this I have get file content with help of below,

$ch = curl_init();
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch,CURLOPT_URL,$data[$k]['doc_url']);
$data = curl_exec($ch);
curl_close($ch);
echo"<pre>";print_r($data);die;

it gives me empty output without file contect

I have also add below code

$content = base64_encode(file_get_contents(urlencode($data[$k]['doc_url']))); $data[$k]['doc_content'] = "$content";

它给我的错误是,无法打开流:PATH中没有这样的文件或目录...

ss1stshoo 回答:流明-file_get_contents给出HTTP_INTERNAL_SERVER_ERROR的错误

可能是您尝试访问的URL阻止了您尝试从其服务器获取内容的方式吗? 也许您应该使用具有所有相关设置的CURL。 我知道重复请求的最好方法是在chrome上打开开发人员控制台,然后在“ Newtork”选项卡上找到您尝试模仿的请求。右键单击->复制->复制为CURL(cmd),然后将其粘贴到此处以接收等效的PHP CURL代码: https://incarnate.github.io/curl-to-php/ 希望它对您有帮助,如果不能,您能否扩大您要到达的目的地?

祝你好运

,

首先,您可以将上下文设置为这种请求:

$options = array(
    'http' => array(
        'protocol_version' => '1.0','method' => 'GET'
    )
);
$context = stream_context_create($options);

尝试像这样获取文件的路径:

$api = "http://PATH_TO_YOUR_FILE?param=optional_query_params";
$response = file_get_contents($api,false,$context);

祝你好运!

本文链接:https://www.f2er.com/3168800.html

大家都在问