Server returned HTTP response code: 403 for URL
六金 2016-07-12 09:34:25 自己做的一个小程序,在获取天气预报的Api时出现禁止访问,有谁知道吗?
java.io.IOException: Server returned HTTP response code: 403 for URL: http://m.weather.com.cn/data/101270803.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at Weather.<init>(Weather.java:44)
at Weather.main(Weather.java:112)
以下是代码
URL url = new URL("http://m.weather.com.cn/data/" + Ctiyid + ".html");
connectionData = url.openConnection();
connectionData.setRequestProperty("User-Agent", "Mozilla/4.0(compatible; MSIE 5.0; Windows NT; DigExt)");
connectionData.setConnectTimeout(5000);
connectionData.setReadTimeout(60000);
br = new BufferedReader(new InputStreamReader(connectionData.getInputStream(), "UTF-8"));