java Android ksoap2 通过 https

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2248147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:17:37  来源:igfitidea点击:

Android ksoap2 via https

javaandroidsoapksoap2

提问by Jonathan D

has any one been able to connect to a soap server using ksoap2 android via https?

有没有人能够通过https使用kso​​ap2 android连接到soap服务器?

I keep getting the error that "Hostname <###>was not verified"

我不断收到“主机名 <###> 未验证”的错误

I'm doing

我正在做

AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);
androidHttpTransport.call(SOAP_ACTION, envelope);

apparently looking back at other ksoap which isn't for android your ment to us a different call to connect via https, but i can't find a way to do it in the android version.

显然,回顾其他不适用于 android 的 ksoap,您向我们提出了通过 https 连接的不同调用,但我找不到在 android 版本中执行此操作的方法。

Anyone found a way about or know the call im ment to use?

任何人都找到了一种方法或知道调用 im ment 使用?

thanks for you help

谢谢你的帮助

采纳答案by johanson

android ksoap2 2.5.2 is out which supports https

支持 https 的 android ksoap2 2.5.2 出来了

http://code.google.com/p/ksoap2-android/

http://code.google.com/p/ksoap2-android/

the problem is i dont quite sure how to use it

问题是我不太确定如何使用它

HttpsTransportSE aht = new HttpsTransportSE(host, port, file, timeout)

what shoud i enter for "file" parameter? anybody have any idea?

我应该为“文件”参数输入什么?有人有任何想法吗?

btw AndroidHttpTransport is deprecated in the latest version of ksoap2

btw AndroidHttpTransport 在最新版本的 ksoap2 中已弃用

回答by vlerenc

Well, you'll need to do two things on Android devices:

那么,您需要在 Android 设备上做两件事:

  1. For SSL you need to trust the server certificate. You can either install a fake trust manager like here (http://groups.google.com/group/android-developers/browse_thread/thread/1ac2b851e07269ba/c7275f3b28ad8bbc?lnk=gst&q=certificateand then call allowAllSSL() before you do any SSL communication/call to ksoap2) or put some more effort into this, make it safer and follow the instructions of saxos, I guess.
  2. Then you need to use ksoap2-android or more specifically the class (KeepAlive)HttpsTransportSE like this new KeepAliveHttpsTransportSE(host, port, file, timeout);. The parameters go into a URL object, so e.g. to access a Jira installation it's something like new KeepAliveHttpsTransportSE("host.whatever", 443, "/rpc/soap/jirasoapservice-v2", 1000)
  1. 对于 SSL,您需要信任服务器证书。您可以安装一个像这里这样的假信任管理器(http://groups.google.com/group/android-developers/browse_thread/thread/1ac2b851e07269ba/c7275f3b28ad8bbc?lnk=gst&q=certificate然后在你做任何事情之前调用 allowAllSSL() SSL 通信/调用 ksoap2) 或为此付出更多努力,使其更安全并按照 saxos 的说明进行操作,我猜。
  2. 然后你需要使用 ksoap2-android 或更具体的类 (KeepAlive)HttpsTransportSE 像这样new KeepAliveHttpsTransportSE(host, port, file, timeout);。参数进入一个 URL 对象,所以例如访问 Jira 安装它就像new KeepAliveHttpsTransportSE("host.whatever", 443, "/rpc/soap/jirasoapservice-v2", 1000)

Btw.: I wrote on "Android devices", because I find it useful to test the stuff first in a J2SE environment and here the (KeepAlive)HttpsTransportSE stuff is missing in the lib (I used ksoap2-j2se-full-2.1.2.jar). Just get the sources for the three classes HttpsTransportSE, KeepAliveHttpsTransportSE, and HttpsServiceConnectionSE from ksoap2-android and put them into your J2SE project and use them. It works and is a productivity improvement to get the first steps with an unknown web service (if you know the web service and how to tweak ksoap2, it's of no use, but it was handy for me as I was new to ksoap2 and its android spin-off).

顺便说一句:我写在“Android 设备”上,因为我发现首先在 J2SE 环境中测试这些东西很有用,而这里的 (KeepAlive)HttpsTransportSE 东西在 lib 中丢失了(我使用了 ksoap2-j2se-full-2.1.2 。罐)。只需从 ksoap2-android 获取三个类 HttpsTransportSE、KeepAliveHttpsTransportSE 和 HttpsServiceConnectionSE 的源代码,并将它们放入您的 J2SE 项目中并使用它们。它可以工作,并且可以提高工作效率,以使用未知的 Web 服务迈出第一步(如果您了解 Web 服务以及如何调整 ksoap2,则它没有用,但它对我来说很方便,因为我是 ksoap2 及其 android 的新手摆脱)。

回答by Ravishankar V

You can set the filename as empty string (""). Looking at the source code of ksoap it passes the parameter to java.net.URL and from the Sun Javadoc it refers to file - "the file on the host". I have given up trying to use ksoap2 for SOAP https calls. Issue is with the way Android processes SSL connections. The only solution seems to be creating a local keystore to store the SSL certificate and writing a wrapper around the Apache Httpclient to use the certificate. So I might as well implement these calls using REST. Guess that's what Google wants us to do.

您可以将文件名设置为空字符串 ("")。查看 ksoap 的源代码,它将参数传递给 java.net.URL 并从 Sun Javadoc 中引用文件 - “主机上的文件”。我已经放弃尝试将 ksoap2 用于 SOAP https 调用。问题在于 Android 处理 SSL 连接的方式。唯一的解决方案似乎是创建一个本地密钥库来存储 SSL 证书并围绕 Apache Httpclient 编写包装器以使用该证书。所以我不妨使用 REST 来实现这些调用。猜猜这就是 Google 希望我们做的。