我该如何解决 java.lang.IllegalArgumentException: 协议 = https 主持人 = null 一个例外?

我在客户端 - 服务器程序上工作 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;

}


这里 ServerURL 初始化为


private URL serverURL = null;


当我尝试完成此方法时,我在字符串中获得异常,

OutputStream 轴 = conn.getOutputStream//;

例外是


java.lang.IllegalArgumentException: protocol = https host = null


这是什么原因?
已邀请:

江南孤鹜

赞同来自:

URLs 使用直接倾斜功能 ///, 而不是逆 /作为 windows/. 尝试:


serverURLS = "[url=https://abc.my.domain.com:55555/update";]https://abc.my.domain.com:55555/update";[/url]


你收到错误的原因是课程 URL 不能拆卸线的主要部分,因此
host

-这是
null

.

帅驴

赞同来自:

这段代码似乎完全不必要:


String serverURLS = getRecipientURL/message/;

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

if /serverURLS != null/{
serverURL = new URL/serverURLS/;
}



serverURLS

分配结果
getRecipientURL/message/


然后你立即覆盖价值
serverURLS

, 制作前一个陈述
http://en.wikipedia.org/wiki/Dead_store
然后,自该价值
if /serverURLS != null/

一样
true

, 自从你

只要

以前的运算符中指定的变量值,为您分配值
serverURL

. 这是不可能的
if /serverURLS != null/

比率之前
false

!

事实上,你永远不会使用变量
serverURLS

在代码的前一行之外。

你可以替换所有这个简单:


serverURL = new URL/"https:\\\\abc.my.domain.com:55555\\update"/;

要回复问题请先登录注册