我正在使用struts1做项目。我正在使用罗马获取RSS提要,但有两个条件失败:
为了避免这种情况,我该怎么办?
发布于 2016-04-02 16:04:54
大约403
有些提要似乎有一些保护(对于DDOS),因此基于用户代理(在您的例子中是"Java"),它们拒绝您读取提要,因此您必须设置自己的用户代理(如firefox用户代理),然后才能像这样打开连接
System.setProperty("http.agent", USER_AGENT);
URLConnection openConnection = url.openConnection();
is = url.openConnection().getInputStream();
if ("gzip".equals(openConnection.getContentEncoding())) {
is = new GZIPInputStream(is);
}
InputSource source = new InputSource(is);
input = new SyndFeedInput();
syndicationFeed = input.build(source);
XmlReader reader = new XmlReader(url);
syndicationFeed = input.build(reader);我当前的USER_AGENT字符串是
"Mozilla/5.0 (WindowsNT10.0;WOW64;rv:41.0) Gecko/20100101 Firefox/41.0";
https://stackoverflow.com/questions/9238649
复制相似问题