php - 通过浏览器的 cURL 超时
问题描述
我有一个非常奇怪的情况。我有通过 cURL 访问的第三方资源 url。我在终端和浏览器中使用相同的类。它在终端上工作正常,但是当我通过 ajaxd 从浏览器请求访问相同的 url 和类时,我得到错误号 28(超时)。
我花了两天时间调试,但找不到任何东西。可能是什么问题呢?
更新:以下是代码:
$this->headers = [
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Authorization: Basic c29hdXNlcjpzb2F1c2VyMTIz",
"SOAPAction: \"getTenantUnitDetails\"",
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->soapUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
$ch_response = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
}
return $ch_response;
解决方案
推荐阅读
- r - 遍历忽略但保留 R 中的 NA 值的列
- laravel - 在 laravel vue 项目中使用 laravel mix 如何在所有组件中包含 scss 文件?
- dom - 如何将我的功能调制为单独的并行测试?
- python - Django 模板语法错误
- php - Craft CMS 允许在直接访问 /checkout 链接时实现零销售
- oracle - Oracle 中的连接池大小概念
- javascript - 如何移动下拉框下方的购买按钮?
- ruby-on-rails - 红宝石单线故障?
- c++ - 迭代 std::set
,如何跟踪哪些要删除? - html - 如何在html中以特定格式显示sql数据