Basic HTTP Authentication Using KSOAP for Android

I need to use a SOAP web service using Android.

The problem is that before requesting a specific function, I need to authenticate the client using a basic HTTP request.

Do you know how to do this with KSOAP?

Until now, I tried to use the overloaded httpsTransportSE.call () method, as it suggests specifying additional headers for the http connection

(link: https://github.com/mosabua/ksoap2-android/blob/master/ksoap2-j2se/src/main/java/org/ksoap2/transport/HttpTransportSE.java )

headerPropertyList.add(new HeaderProperty("Authorization", "Basic : dXNlcjpwYXNz"));

"cdXNlcjpwYXNz" is the string "user: pass" encoded in the base 64

 public List call(String soapAction, SoapEnvelope envelope, List headers)
    * @param headers a list of HeaderProperties to be http header properties when establishing the connection



private static final String SOAP_ACTION = "someaddress/IPortReporting/GetPortStatus";
private static final String METHOD_NAME = "methodname";
private static final String NAMESPACE = "http://ssn.someaddress/2.0/";
private static final String URL = "new.someaddress/functionName.svc";




SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        Request.addProperty("MessageId", "1");

        SoapSerializationEnvelope soapEnvelop = new SoapSerializationEnvelope(
                11);
        //soapEnvelop.headerOut = addHeaders(); 
        soapEnvelop.dotNet = true;
        soapEnvelop.setOutputSoapObject(Request);


        List<HeaderProperty> headerPropertieList = new ArrayList<HeaderProperty>();
        headerPropertyList.add(new HeaderProperty("Authorization", "Basic : cG9ydHdzOjEyM3F3ZUFTRA=="));
        //HeaderProperty headerProperty = new HeaderProperty()

        HttpsTransportSE httpsse = new HttpsTransportSE(URL, 443, "", 5000);



        try {
            httpsse.call(SOAP_ACTION, soapEnvelop, headerPropertyList);
            //httpsse.call(SOAP_ACTION, soapEnvelop);

            SoapPrimitive resultString = (SoapPrimitive) soapEnvelop
                    .getResponse();
            tv.setText("Status: ");
        } catch (Exception e) {
            tv.setText("Some error," + " "
                    + e.getMessage());
        }

But I got the message "permission denied."

+5
6

. , .Net- Android. ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar

String NAMESPACE = "http://www.namespace.com/";
String METHOD_NAME = "MethodName";
String SOAP_ACTION = "http://www.namespace.com/MethodName";
String URL = "https://www.namespace.com/services/Service.asmx";

      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
          // Set all input params   
          request.addProperty("property", "value");   
          SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
         // Enable the below property if consuming .Net service
     envelope.dotNet = true;
     envelope.setOutputSoapObject(request);

     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
     try 
     {
         List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
         headerList.add(new HeaderProperty("Authorization", "Basic " + org.kobjects.base64.Base64.encode("username:password".getBytes())));

         androidHttpTransport.call(SOAP_ACTION, envelope, headerList);
         SoapObject response = (SoapObject)envelope.getResponse();
         //response.getProperty(0).toString();
     }
     catch(Exception e)
     {
         e.printStackTrace();
     }
+10

, HeaderProperty - "Basic dXNlcjpwYXNz" - , ? ( ?)

+4

, Android:

<uses-permission android:name="android.permission.INTERNET" />
+2

. . , - SOAP (.asmx) Android.

- .

,

+2

fooobar.com/questions/342811/... ....

soapEnvelope.headerOut = new Element[1];

this → SoapSerializationEnvelope envelope NAMESPACE this → http://tempuri.org/ my code =>

public Element buildAuthHeader() {
Element h = new Element().createElement(NAMESPACE, "AuthHeader");
Element username = new Element().createElement(NAMESPACE, "Username");
username.addChild(Node.TEXT, "test");
h.addChild(Node.ELEMENT, username);
// Element pass = new Element().createElement(NAMESPACE, "pass");
// pass.addChild(Node.TEXT, pass);
// h.addChild(Node.ELEMENT, pass);
return h;

In VS C #

public class AuthHeader : SoapHeader
{
public string Username;
//public string Password;
}
0
source

All Articles