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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/738778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:36:00  来源:igfitidea点击:

java.net.ConnectException: Connection timed out: connect exception occur

javanetworkingsockets

提问by Dominik Rockenschaub

I have this code, can you help me to solve this problem?
I have written this code:

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

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);

The error listing is:

错误列表是:

   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.access0(Capture.java:83)
        at de.mud.jta.plugin.Capture.actionPerformed(Capture.java:173)
        at de.mud.jta.plugin.Capture.actionPerformed(Capture.java:266)

I am trying this on my local network, so no issue of firewall..
Can anyone help?

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

krunal patel

克鲁纳尔帕特尔

回答by Rangappa Tungal

i got some thing some net, how to add proxy , when i tried this i am not getting Setting in project, configure so.. so please let me know how to do this.. see below for how to do this..

我得到了一些网络,如何添加代理,当我尝试这个时,我没有在项目中设置,这样配置..所以请让我知道如何做到这一点......请参阅下文了解如何做到这一点..

Configure it in the project Settings, tab Configurations, edit current Default profile, tab Server, add proxy settings to the 'Extra JVM parameters', for example add:

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

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

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

回答by Rohit

The address that you are connecting should exist. e.g. if you are opening a connection to localhost on port 8080, then there should be a server listening on that port.

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

回答by Dominik Rockenschaub

maybe a firewall problem? check if you can reach the url through telnet by using: telnet url 80

也许是防火墙问题?使用以下命令检查是否可以通过 telnet 访问 url:telnet url 80