Server returned HTTP response code: 502 for URL:????

llq20107760428 2014-04-21 04:02:37
用Java写爬虫爬取网页返回java.io.IOException: Server returned HTTP response code: 502 for URL: ???
我已设置代理 conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 6.2; " +
"WOW64; rv:20.0) ");
还是无法访问
求各位大神是怎么解决?
...全文
1228 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
自己动手试了没有,就说没区别。
llq20107760428 2014-04-21
  • 打赏
  • 举报
回复
llq20107760428 2014-04-21
  • 打赏
  • 举报
回复
有什么区别吗,这样还是屏蔽吧
  • 打赏
  • 举报
回复
还是改为httpclient 访问吧,原生的毕竟知识基本的,一个网络设置,还是httpclient 封装的比较好。
llq20107760428 2014-04-21
  • 打赏
  • 举报
回复
具体代码: public class HttpRequestUtil { public String Pages(String urlStr) { StringBuffer html = new StringBuffer(); String result = null; try { URL url = new URL(urlStr); URLConnection conn = url.openConnection(); conn.setRequestProperty( "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0)"); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "gb2312"));// 读取网页全部内容 while ((result = in.readLine()) != null) { html.append(result); } in.close(); } catch (final MalformedURLException me) { System.out.println("你输入的URL格式有问题!"); me.getMessage(); } catch (final IOException e) { e.printStackTrace(); } //System.out.println(html.toString()); return html.toString(); } public static void main(String[] args) { HttpRequestUtil h = new HttpRequestUtil(); try { h.Pages("http://ypk.39.net/manual/500164/0/"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
llq20107760428 2014-04-21
  • 打赏
  • 举报
回复
求大神快点回复啊、、、急急急

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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