HttpsURLConnection: Connection Timed out error

前端 未结 5 1837
情深已故
情深已故 2020-12-07 04:21

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;
         


        
5条回答
  •  时光说笑
    2020-12-07 04:49

    Either leave out conn.setDoOutput(true); or conn.setRequestMethod("GET"); because these two statements are contradicting. GET does not allow output and output on the other side means you can't use GET as request method.

    It seems that you are trying to fetch the certificate from the SSL layer of the HTTPS protocol. For this, you do not need to send anythig (hence doOutput is not needed). Instead, the information that you want to get is sent to you as part of the SSL handshake inside of the connection establishing code of the HttpsURLConnection, and the SSLSocket which is part of this.

    This will help you do what you are after: http://www.xinotes.org/notes/note/1088/

提交回复
热议问题