Using java class HttpsURLConnection

前端 未结 9 1435
孤独总比滥情好
孤独总比滥情好 2020-12-14 00:41

I have a small piece of code which basically impements a HTTP-Client, i.e. it POSTS request and works with re RESPONSE. As long as HTTP is concenerned everthing work well. F

相关标签:
9条回答
  • 2020-12-14 01:17

    The above problem is only caused by two issues

    1. Using wrong import
    2. Using http in the string you create url from use instead https
    0 讨论(0)
  • 2020-12-14 01:17

    Change:

    import javax.net.ssl.HttpsURLConnection;
    

    and

    URL url = new URL(serverAddress);
    HttpsURLConnection httpsConn = (HttpsURLConnection) url.openConnection();
    

    Change To:

    import java.net.HttpURLConnection;
    

    and

    URL url = new URL(serverAddress);
    HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
    
    0 讨论(0)
  • 2020-12-14 01:18

    Instead of creating a URL object using standard constructor like

    URL wsURL = new URL(url);
    

    Use

    java.net.URL wsURL = new URL(null, url,new sun.net.www.protocol.https.Handler());
    

    which would solve this problem

    0 讨论(0)
提交回复
热议问题