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

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

问题描述

我正在使用ZOHO API,并尝试使用CURL更新记录。我尝试不同的CURL变化,但它总是返回假。但是当我使用浏览器调用相同的URL时,它工作。

有没有办法他们可以阻止CURL请求?有没有任何其他方式我可以调用该URL使用POSt或可能是GET也做?我花了差不多2-3天。

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.
Is there any way they can block CURL requests? Is there any other way I can call that URL using POSt or may be GET also do? I spent almost 2-3 days. If you are ZOHO API user can you please show me the code that worked for you?

最近的curl我试过的如下:

Recent curl I 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请求不满足的一些参数,它可以决定以不同的方式响应。

Server's 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天全站免登陆