简体   繁体   English

HTTP/1.1 426 需要升级 - Apache2 服务器 (debian 9) 上的 file_get_contents (PHP)

[英]HTTP/1.1 426 Upgrade Required - file_get_contents (PHP) on Apache2 server (debian 9)

First post here, I'm running into an issue I didn't have when working on my local machine /w XAMPP.在这里发表第一篇文章,我遇到了一个在我的本地机器上工作时没有遇到的问题 /w XAMPP。

I've push some basic PHP code on my VPS with a fresh Apache2 and PHP7 install, and one of the file is actually doing a file_get_contents to do a GET request on Trello's API:我已经在我的 VPS 上推送了一些基本的 PHP 代码,并安装了全新的 Apache2 和 PHP7,其中一个文件实际上正在执行 file_get_contents 以在 Trello 的 API 上执行 GET 请求:

$lists = json_decode(file_get_contents("https://api.trello.com/1/boards/<<HIDDEN>>/lists?key={$id}&token={$token}"), true);

The problem is that I'm receiving this HTTP response when doing so:问题是我在这样做时收到了这个 HTTP 响应:

[Tue Aug 24 14:27:14.132294 2021] [:error] [pid 17956] [client <<HIDDEN>>] PHP Warning:  file_get_contents(https://api.trello.com/1/boards/<<HIDDEN>>/lists?key=<<HIDDEN>>&amp;token=<<HIDDEN>>): failed to open stream: HTTP request failed! HTTP/1.1 426 Upgrade Required\r\n in <HIDDEN>/trello.php on line 7, referer: <<HIDDEN>>

I've done some research and I saw that I kinda need to upgrade the call to another HTTP protocol but so far, I have no clues about the way to proceed...我做了一些研究,我发现我有点需要将呼叫升级到另一个 HTTP 协议,但到目前为止,我不知道如何继续......

Any advice, tip?有什么建议吗?

Thanks!谢谢!

Ok, so I still have no clues about how to fix that using file_get_contents , but I found a workaround that seems to work using curl .好的,所以我仍然不知道如何使用file_get_contents解决这个问题,但我找到了一个似乎可以使用curl的解决方法。

If some people are also having the issue, I've replaced the initial request with that:如果有些人也有这个问题,我已经用以下内容替换了最初的请求:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.trello.com/1/boards/<<HIDDEN>>/lists?key={$id}&token={$token}");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2);
    curl_setopt($ch, CURLOPT_HTTPGET, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $lists = json_decode(curl_exec($ch), true);
    curl_close($ch);

Looks like the curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2);看起来像curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2); is doing the job.正在做这项工作。

That's not answering the root question (how to do that with file_get_contents ) but if it can help...那没有回答根本问题(如何使用file_get_contents做到这一点)但如果它可以帮助......

Thanks!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM