我该如何解决java.lang.IllegalArgumentException:protocol = https host = null异常?

Cha*_*ara 7 java ssl exception stream

我正在研究SSL客户端服务器程序,我必须重用以下方法.

private boolean postMessage(String message){
    try{ 
         String serverURLS = getRecipientURL(message);

         serverURLS = "https:\\\\abc.my.domain.com:55555\\update";

         if (serverURLS != null){
             serverURL = new URL(serverURLS);
         }

        HttpsURLConnection conn = (HttpsURLConnection)serverURL.openConnection();

        conn.setHostnameVerifier(new HostnameVerifier() { 
        public boolean verify(String arg0, SSLSession arg1) {
            return true;
        } 
        });

        conn.setDoOutput(true);

        OutputStream os = conn.getOutputStream();

        OutputStreamWriter wr = new OutputStreamWriter(os);

        wr.write(message);

        wr.flush();

        if (conn.getResponseCode() != HttpsURLConnection.HTTP_OK)
            return false;
        else
            return true;

    }
Run Code Online (Sandbox Code Playgroud)

这里ServerURL初始化为

private URL serverURL = null;
Run Code Online (Sandbox Code Playgroud)

当我尝试执行此方法时,我在Line处获得异常,

OutputStream os = conn.getOutputStream();

例外是

java.lang.IllegalArgumentException: protocol = https host = null
Run Code Online (Sandbox Code Playgroud)

这是什么原因?

Aar*_*lla 19

URL使用正斜杠(/),而不是向后斜杠(作为窗口).尝试:

serverURLS = "https://abc.my.domain.com:55555/update";
Run Code Online (Sandbox Code Playgroud)

您收到错误的原因是URL类无法解析字符串的主机部分,因此,hostnull.