通过cURL连接到API时出现问题

时间:2018-11-20 19:20:16

标签: php http curl

我在连接我的一个合作伙伴API时遇到问题。

我可以使用以下代码通过PHP内的cURL连接到API(它将尝试发出30秒的请求,然后使用504 Gateaway超时进行超时)

<?php

// get cURL resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, 'https://api.scanpay.dk/');

// set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// send the request and save response to $response
$response = curl_exec($ch);

// stop if fails
if (!$response) {
  die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}

echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo 'Response Body: ' . $response . PHP_EOL;

// close curl resource to free up system resources 
curl_close($ch);

代码应该返回Forbidden,因为我提供了API密钥。 我试图从服务器终端使用cURL进行相同的调用,但仍然出现此错误

我也试图与我的房东联系,但是他们不能帮助我。

我认为这与防火墙有关。

感谢您的帮助。

0 个答案:

没有答案