Java 用户代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1072356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java User Agent
提问by Midhat
I have recently started seeing user agents like Java/1.6.0_14 (and variations) on my site
我最近开始在我的网站上看到像 Java/1.6.0_14(和变体)这样的用户代理
What does this mean. Is it a browser or bot or what
这是什么意思。是浏览器还是机器人还是什么
回答by dimo414
This likely means someone is crawling your website using Java. This isn't much of anything to be concerned about unless you notice the crawler using large amounts of your bandwidth or not respecting your robots.txt file. Usually legitimate crawlers will take the time to create custom user agent to make it easy to contact the crawler if you have a problem, but even if they're using the default user agent, it's more than likely perfectly benign.
这可能意味着有人正在使用 Java 抓取您的网站。这没什么好担心的,除非您注意到爬虫使用了大量带宽或不尊重您的 robots.txt 文件。通常合法的爬虫会花时间创建自定义用户代理,以便在遇到问题时轻松联系爬虫,但即使他们使用默认的用户代理,也很可能是完全无害的。
However, if you do notice a spike in 404 hits or lotsof hits from the Java client, you're likely under attack by spammers looking for security holes in your website. If your site is built well, there's not a whole lot they can do other than burn some of your bandwidth, but if they find a security hole, they'll be sure to exploit it. Dealing with spammers properly is beyond the scope of this answer, but a scorched earth solution (which will work as a short term fix at the very least) would be to block all user agents that contain the string 'java'.
但是,如果您确实注意到来自 Java 客户端的404 次点击或大量点击次数激增,那么您很可能会受到垃圾邮件发送者的攻击,他们正在寻找您网站中的安全漏洞。如果您的网站构建良好,除了消耗您的一些带宽外,他们无能为力,但如果他们发现安全漏洞,他们一定会利用它。正确处理垃圾邮件发送者超出了本答案的范围,但焦土解决方案(至少可以作为短期修复)将阻止所有包含字符串“java”的用户代理。
回答by John T
It means your site is being accessed through the JVM on someones machine. It could be a crawler or simply someone scraping data. You can replicate the user-agent string using the HttpURLConnectionclass. Here is a sample:
这意味着正在通过某人机器上的 JVM 访问您的站点。它可能是一个爬虫,也可能只是一个抓取数据的人。您可以使用HttpURLConnection类复制用户代理字符串。这是一个示例:
import java.net.*;
public class Request {
public static void main(String[] args) {
try {
URL url=new URL("http://google.ca");
HttpURLConnection con=(HttpURLConnection)url.openConnection();
con.connect();
System.out.println(con.getResponseCode());
} catch (Exception e) {
e.printStackTrace();
}
}
}
回答by William Brendel
Java's HttpURLConnectionclass will send the JVM version information as the User-Agentheader.
Java 的HttpURLConnection类将 JVM 版本信息作为User-Agent标头发送。

