首页 > 解决方案 > PHP Curl 请求导致 504 网关超时

问题描述

我不确定这里的问题是什么,但我一直在使用以下网站生成 PHP curl 请求:

https://reqbin.com/req/php/5k564bhv/get-request-with-bearer-token-authorization-header

当我从该站点运行请求时,它会立即运行。

但是,当我复制并粘贴他们正在使用的确切PHP 代码时,会导致504 gateway timeout错误。

<?php

$url = "https://example.com/api";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PUT, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "Accept: application/json",
   "Authorization: Bearer f03qawdqdqz47vuy1j02313215gazpfkwkfwpkngbpwd1xxlgvfew",
   "Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$data = '{"var":"value","anothervar":"anothervalue"}';

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);

?>

标签: phpubuntunginxcurl

解决方案


推荐阅读