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"));
...全文
558 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧