服务器可以阻止 curl 请求吗? [英] Can servers block curl requests?

查看:42
本文介绍了服务器可以阻止 curl 请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 ZOHO API 并尝试使用 cURL 更新记录.我尝试了不同的 cURL 变体,但它总是返回false".但是当我使用浏览器调用相同的 URL 时,它可以工作.

I am working on ZOHO API and trying to update the record using cURL. I tried different cURL variations, but it always returns "false". But when I call the same URL using a browser, it works.

有什么办法可以阻止 cURL 请求?有没有其他方法可以使用 POST 或 GET 请求调用该 URL?

Is there any way they can block cURL requests? Is there any other way I can call that URL using a POST or maybe a GET request?

我试过的cURL代码如下:

The cURL code I have tried is as below:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);

推荐答案

服务器本身无法阻止 cURL 请求,但可以阻止任何他们不喜欢的请求.如果服务器检查了您的 cURL 请求不满足的某些参数,它可能会决定做出不同的响应.

Servers cannot block cURL requests per se, but they can block any request that they do not like. If the server checks for some parameters that your cURL request does not satisfy, it could decide to respond differently.

在绝大多数情况下,这种行为差异是由 HTTP 请求标头的存在(或不存在)和值触发的.例如,服务器可能会检查 User-Agent 标头是否存在并具有有效值(它还可以检查许多其他内容).

In the vast majority of cases, this difference in behavior is triggered by the presence (or absence) and values of the HTTP request headers. For example, the server might check that the User-Agent header is present and has a valid value (it could also check lots of other things).

要了解来自浏览器的 HTTP 请求是什么样的,请使用 HTTP 调试代理,例如 Fiddler或浏览器的开发者工具.

To find out what the HTTP request coming from the browser looks like, use an HTTP debugging proxy like Fiddler or your browser's developer tools.

要将您自己的标头添加到您的 cURL 请求中,请使用

To add your own headers to your cURL request, use

curl_setopt($ch, CURLOPT_HTTPHEADER, array('HeaderName: HeaderValue'));

这篇关于服务器可以阻止 curl 请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆