java.net.ConnectException:连接超时:发生连接异常

时间:2009-04-10 20:30:31

标签: java networking sockets

我有这个代码,你能帮我解决这个问题吗? 我写了这段代码:

out = new DataOutputStream(urlConnection.getOutputStream());//exception occur

String content = (String) remoteUrlList.get(urlID + ".params");
content = (content == null ? "" : content + "&") + "content=" +   URLEncoder.encode(textArea.getText());
if (debug > 0) System.err.println("Capture: " + content);
out.writeBytes(content);
out.flush();
out.close();

// retrieve response from the remote host and display it.
if (debug > 0) System.err.println("Capture: reading response");
in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String str;
while (null != ((str = in.readLine()))) {
  System.out.println("Capture: " + str);
}
in.close();

doneDialog.pack();
doneDialog.setVisible(true);

错误列表是:

   at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.Socket.connect(Socket.java:519)
        at java.net.Socket.connect(Socket.java:469)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
        at sun.net.www.http.HttpClient.(HttpClient.java:233)
        at sun.net.www.http.HttpClient.New(HttpClient.java:306)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:795)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:743)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:654)
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:832)
        at de.mud.jta.plugin.Capture.saveFile(Capture.java:339)
        at de.mud.jta.plugin.Capture.access$200(Capture.java:83)
        at de.mud.jta.plugin.Capture$4.actionPerformed(Capture.java:173)
        at de.mud.jta.plugin.Capture$10$1.actionPerformed(Capture.java:266)

我在我的本地网络上尝试这个,所以没有防火墙问题。
有人可以帮忙吗?

krunal patel

3 个答案:

答案 0 :(得分:1)

我有一些东西网,如何添加代理,当我尝试这个我没有得到项目中的设置,配置所以..所以请让我知道如何做到这一点..请参阅下面的如何做到这一点。

在项目设置,选项卡配置,编辑当前默认配置文件,选项卡服务器,将代理设置添加到'额外JVM参数'中进行配置,例如添加:

-Dhttp.proxyHost = myproxyserver.com -Dhttp.proxyPort = 80

答案 1 :(得分:0)

您要连接的地址应该存在。例如如果要在端口8080上打开与localhost的连接,那么应该有一个服务器正在侦听该端口。

答案 2 :(得分:0)

可能是防火墙问题?检查您是否可以使用telnet url 80

通过telnet访问该URL