Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

java - Android ksoap2 via https

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

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.

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

thanks for you help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  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=certificate and 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)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...