php - 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);
?>
解决方案
推荐阅读
- java - Apache Solr 处理数十万个请求
- javascript - 为什么在全局范围内的 for-of 循环中使用 const 会抛出 TypeError,但在函数内它可以工作?
- java - Coin Change - Java 未能通过示例 3
- python - python virtualenv中硒的chrome web驱动程序错误
- xslt - 遍历 XSLT 中的列表并将其分配给 Java 对象
- python-3.x - 在线程上运行函数会出错
- python - Psycopg2 不仅接受 None (Nonetype) 作为使用 %s 时可以为 Null 的单元格条目,但不接受 f 字符串
- java - 在没有 Class.forName() 或系统属性的情况下如何加载 JDBC 驱动程序?
- hybris - 使用 Smartedit 的本地化 nm 关系时如何修复 ClassCastException?
- c# - 如何制作一种方法来旋转多个字符?