可能會遇到“java.io.IOException: Server returned HTTP response code: 403 for URL”的錯誤信息。
通常是因為服務器的安全設置不接受Java程序作為客戶端訪問,解決方案是設置客戶端的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)");