如何确定 HTTP 请求是来自浏览器还是来自 Web 服务之类的其他东西? [英] How do I determine if a HTTP request came from a browser or something else like a web service?

查看:81
本文介绍了如何确定 HTTP 请求是来自浏览器还是来自 Web 服务之类的其他东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何确定 HTTP 请求是来自浏览器还是来自网络服务之类的其他东西?

How do I determine if a HTTP request came from a browser or something else like a web service?

我知道有一个用户代理,但这似乎主要用于网络浏览器.例如,我知道请求来自谷歌地图或 youtube.请求来自连接的设备.

I am aware that there is a User Agent, but this seems mainly for web browsers. For instance I do I know the request came from a google maps or youtube. The request are coming off a tethered device.

如果他们有不同的用户代理,我可以举个例子吗?

If they have a different User Agent, can I get an example.

谢谢.

推荐答案

绝对无法确定请求是来自浏览器还是其他发出 HTTP 请求的东西.

There is absolutely no way to know with certainty if a request came from a browser or something else making an HTTP request.

HTTP 协议允许客户端任意设置用户代理.

The HTTP protocol allows for the client to set the User Agent arbitrarily.

可以尝试确定另一端的东西是否是浏览器,例如通过执行 JavaScript 并测量结果.但是,有些机器人可以执行 JavaScript,但并非所有浏览器都执行 JavaScript,因此测试类型永远不可能完美.

One can attempt to determine if the thing on the other end is a browser e.g. by executing JavaScript and measuring the outcome. However, some bots can execute JavaScript, and not all browsers execute JavaScript so that type of test can never be perfect.

行为良好的机器人"(如常见的搜索引擎蜘蛛)将使用特定于它们的用户代理来识别自己.这里有一个非常全面的用户代理列表:

Well-behaved "bots" (like common search engine spiders) will identify themselves using a User Agent specific to them. There's a pretty comprehensive list of user agents here:

http://www.user-agents.org/

http://www.botsvsbrowsers.com/

这篇关于如何确定 HTTP 请求是来自浏览器还是来自 Web 服务之类的其他东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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