是“硬编码"吗?用户代理足以让程序在多台计算机上运行吗? [英] Is a "Hard Coded" user agent enough for a program to work on multiple computers?

查看:37
本文介绍了是“硬编码"吗?用户代理足以让程序在多台计算机上运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 idHttp 登录一些站点并下载一些文件,我想知道因为我的程序将在具有不同窗口和软件的多台计算机上运行时我说例子:

I'm using idHttp to login to some sites and download a few files, and I was wondering since my program is going to be run on multiple computers with different windows and softwares when I say for example:

idHttp.userAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41';

够了吗?或者我是否必须以某种方式从某处提取该计算机的正确用户代理信息并发送?我的意思是硬编码用户代理是可行的方法,并且足以让程序在多台计算机上兼容吗?

Is it enough? Or do I have to somehow extract the correct useragent information of that computer from somewhere and send that? I mean is a hard coded user agent the way to go and enough for a program to be compatible on multiple computers?

推荐答案

登录一些网站并下载一些文件

login to some sites and download a few files

通过这种方式,您很可能正在处理 cookie.这与那些想要索引互联网并或多或少地请求任何东西而无需登录任何地方的凭据的搜索引擎不同.

By this you're most likely dealing with cookies. This is a difference to i.e. search engines which want to index the internet and more or less request anything, without having credentials to log in anywhere.

我的程序将在具有不同窗口和软件的多台计算机上运行

my program is going to be run on multiple computers with different windows and softwares

这与您的程序无关.

'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41'

'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41'

通过这种方式,服务器希望您能够像您命名的 Internet 浏览器一样运行.你显然不会.

By this the server expects you being able to behave just like the internet browsers you're naming. Which you obviously won't.

在您的情况下,您没有交互式 Internet 浏览器 - 您有一个自动机器人,而那些应该有一个适当的用户代理.如果您阅读 https://en.wikipedia.org/wiki/User_agent#Format_for_automated_agents_.28bots.29 你会发现像这样的用户代理更适合你的程序:网站所有者可以识别你(这既有优点也有缺点),还可以在你的 URI 下查找更多关于你的目的的信息给他们:

In your case you don't have an interactive internet browser - you have an automated bot, and those should have an appropriate useragent. If you read https://en.wikipedia.org/wiki/User_agent#Format_for_automated_agents_.28bots.29 you'll see that a useragent like this would be more fitting to your program: website owners can identify you (which can have both advantages and disadvantages) and also look up more about your purpose under the URI you're giving them:

MyProgram/1.0 (+http://myprogram.org/what_i_am_doing.html) 

这篇关于是“硬编码"吗?用户代理足以让程序在多台计算机上运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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