-->

Webservice Http Authentication - KSOAP2 on Android

2019-01-26 18:45发布

问题:

I have been searching the web for a while now, but wasn't able to find a appropriate solution for my problem. This article does not really help either, because the classes and methods used are not present in ksoap2 for android: Basic HTTP authentication using KSOAP for android

I am trying to access a SAP webservice, which I set up in the sap soa manager. The webservice requires basic authentication in the http header. Accessing this web service by soapUI is not a problem, because it is possible to set up http authentication there.

My Problem: I want to access the web service with a android device and I want to use KSOAP2 for Android because I already have some experience with that libary. My problem is that I don't know how to authenticate to the webservice?

Has anyone had a similar problem and knows how to solve it? I would be grateful if you could help me!

回答1:

I hope it is not too late. That is how I access SAP webservice with KSOAP:

List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
headers.add(new HeaderProperty("Authorization", "Basic XXXXXXXXXX"));
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
Object result = null;               
final Object response = androidHttpTransport.call(SOAP_ACTION, envelope, headers);

Replace the XXXXXXXX with the encoded hash of your username and password. To get it just look in soapUI raw header request. Hope it helps.