使用 C# (VS2008) 的 WebRequest 工作正常,但在 Java (Ecplise) 上不行

发布于 2024-09-03 00:42:06 字数 575 浏览 1 评论 0原文

我正在尝试从网页读取数据,并且必须使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱武穆 2024-09-10 00:42:06

我正在使用这段代码:
URL yahoo = 新 URL("http://www.yahoo.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader = new BufferedReader(
新的输入流读取器(
yc.getInputStream()));
字符串输入行;

            while ((inputLine = in.readLine()) != null) 
                System.out.println(inputLine);
            in.close();

从这里找到: 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;

            while ((inputLine = in.readLine()) != null) 
                System.out.println(inputLine);
            in.close();

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文