2

我正在使用ksoaplib 调用webservice. 在某些情况下,服务运行正确,但如果它给出的主机名未得到验证,下面是我的调用代码webservice

 HttpTransportSE httpTransport = new HttpTransportSE(URL, MessageConstant.TIMEOUT_TIME);
            httpTransport.debug = true; // this is optional, use it if you don't want to use a packet sniffer to check what the sent message was (httpTransport.requestDump)
            httpTransport.call(SOAP_ACTION, envelope); // send request

这是我的日志猫

java.io.IOException: Hostname 'XXX.XX.XXX.XXX' was not verified
at libcore.net.http.HttpConnection.verifySecureSocketHostname(HttpConnection.java:223)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:446)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:152)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
4

2 回答 2

1

这个链接有几个可能的原因;没有任何答复被标记为“已接受”:

你也应该看看这里:

发生这种情况的一个原因是服务器配置错误。服务器配置的证书没有与您尝试访问的服务器匹配的主题或主题备用名称字段。可以将一个证书用于许多不同的服务器。

例如,与openssl s_client -connect google.com:443 | openssl x509 -text您一起查看 google.com 证书可以看到一个支持 *.google.com 的主题,但也支持 *.youtube.com、*.android.com 等的主题替代名称。仅当证书未将您连接的服务器名称列为可接受时,才会出现该错误。

于 2013-10-04T19:27:13.793 回答
1

验证您的主机为

   HttpsURLConnection.setDefaultHostnameVerifier(new HostVerifier());


 public class HostVerifier implements HostnameVerifier {

@Override
public boolean verify(String hostname, SSLSession session) {
    Log.i(TAG, "HOST NAME " + hostname);
    if (hostname.contentEquals("XXX.XX.XXX.XXX")) {
        Log.i(TAG, "Approving certificate for host " + hostname);
        return true;
    }
    return false;
 }
}
于 2016-04-12T07:55:02.167 回答