可能會(huì)遇到“java.io.IOException: Server returned HTTP response code: 403 for URL”的錯(cuò)誤信息。
通常是因?yàn)榉?wù)器的安全設(shè)置不接受Java程序作為客戶端訪問,解決方案是設(shè)置客戶端的User Agent
將
URL httpUrl = new URL(rssURL);
改為
URLConnection con = new URL(url).openConnection();
con.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows XP; DigExt)");