简体   繁体   English

使用CURL击中API

[英]API hit using CURL

Am trying to access an API using CURL I can access the API from my browser. 尝试使用CURL访问API时,我可以从浏览器访问API。 But cannot get the data from the same api(using the same API key) using curl. 但是无法使用curl从相同的api(使用相同的API密钥)获取数据。

I am getting this error. 我收到此错误。 403 Developer Over Qps 403 Qps开发人员

Please let me know what can be the reason for this. 请让我知道这可能是什么原因。

Earlier it was working. 较早时它正在工作。 I am facing this issue for the past 2 days.!! 我在过去2天里都遇到这个问题。

please check the code below: 请检查以下代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.perfb.com/api/api.php?requestmethod=json&responsemethod=xml');

curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vJson);

$response = curl_exec($ch);
$info = curl_getinfo($ch);
echo '<pre>';
print_r($info);exit;

Qps means Queries Per Second Qps表示每秒查询

Are you hitting the server repeatedly with curl in a loop for example? 例如,您是否反复循环卷曲服务器? Try adding a pause after each call and see if that works. 尝试在每次通话后添加一个暂停,看看是否可行。

That error usually signifies that you're hitting the server too often (ie developer over allowed queries per second). 该错误通常表示您经常访问服务器(例如,开发人员每秒超过允许的查询次数)。 Slow down your code, put some delays in. In browser, you're doing it manually, so it's likely quite a bit slower than your code. 放慢代码的速度,增加一些延迟。在浏览器中,您是手动进行的,因此它可能比您的代码慢很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM