首页 > 解决方案 > 通过浏览器的 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;

更新 2:这是来自浏览器的请求,它不起作用。 在此处输入图像描述

这是来自正在工作的终端的请求。 在此处输入图像描述

标签: phpapachecurl

解决方案


推荐阅读