使用 C# (VS2008) 的 WebRequest 工作正常,但在 Java (Ecplise) 上不行
我正在尝试从网页读取数据,并且必须使用 Java 来完成。 当我尝试使用 Java 在 Eclipse 中执行此操作时,出现超时错误: java.net.ConnectException:连接超时:连接 (使用 HttpURLConnection):
URL yahoo = new URL("http://www.yahoo.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
为了了解问题出在哪里,我尝试使用 c# 和 VS2008 执行相同的任务,它工作得很好,根本没有超时。
我是在工作中这样做的,所以有防火墙,但我没有相关信息。
这可能是什么原因?
谢谢! 丹尼尔
I'm trying to read data from a webpage, and I have to do it using Java.
When I try to do it in Eclipse using Java i'm getting time out error:
java.net.ConnectException: Connection timed out: connect
(Using HttpURLConnection):
URL yahoo = new URL("http://www.yahoo.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
In order to understand where is the problem I tried doing the same task using c# and VS2008, and it worked perfectly fine, no time out at all.
I'm doing this from work so there's a firewall but I don't have information about it.
What can be the reason for this?
Thanks!
Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用这段代码:
URL yahoo = 新 URL("http://www.yahoo.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader = new BufferedReader(
新的输入流读取器(
yc.getInputStream()));
字符串输入行;
从这里找到: http://java.sun.com/ docs/books/tutorial/networking/urls/readingWriting.html
我是在工作中这样做的,所以有防火墙,但我没有有关它的信息。
I'm using this code:
URL yahoo = new URL("http://www.yahoo.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
found from here: http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
I'm doing this from work so there's a firewall but I don't have information about it.