HttpsURLConnection:连接超时错误 [英] HttpsURLConnection: Connection Timed out error

查看:689
本文介绍了HttpsURLConnection:连接超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的代码,用于设置与谷歌的https连接并打印获得的响应。

I have a simple code for setting up a https connection to google and printing the response obtained.

import java.io.OutputStreamWriter;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;


public class SendCertReq 
{
public static void main(String[] args) throws Exception 
{
     URL url = new URL("https://www.google.co.in/");
     HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
     conn.setRequestMethod("GET");
     conn.setDoOutput(true);
     OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
     wr.close();
     System.out.println(conn.getResponseMessage());
}
}

当我尝试运行它时出现以下错误。

I get the following error when I try to run it.

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at SendCertReq.main(SendCertReq.java:16)

任何人都可以指导我。从早上起我就一直在吃脑袋。

Can anyone please guide me. I've been eating my head since morning trying to figure it out.

推荐答案

没有办法确切地说出错了什么因为超时不是预期的行为,即使发送格式错误的请求,你的方式也是如此。这是我用来调试的一般程序。

There is no way to tell exactly what is wrong since timing out is not expected behavior, even when sending a malformed request, the way you are. This is the general procedure I use to debug, however.

这篇关于HttpsURLConnection:连接超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆