Call web service with authentication (login and password) from android app
<p>From the past few days, I have been working on an Android code to call a local web service. I am using ksoap2 libraries for Android "ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar" to call my SOAP web service created in .NET
The issue is that before request for a particular function I need to authenticate a client using basic http request.</p>

<p>This is my code : </p>

<pre><code>public String CallSoapConnexion(String login, String mdp) {
    SoapObject request = new SoapObject(nms, mth);
    PropertyInfo pi = new PropertyInfo();
    pi.setName("login");
    pi.setValue(login);
    pi.setType(String.class);
    request.addProperty(pi);
    pi = new PropertyInfo();
    pi.setName("mdp");
    pi.setValue(mdp);
    pi.setType(String.class);
    request.addProperty(pi);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);

    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport = new HttpTransportSE(urlHttp);

    List&lt;HeaderProperty&gt; headerList = new ArrayList&lt;HeaderProperty&gt;();

    headerList
            .add(new HeaderProperty("Authorization", "Basic "
                    + org.kobjects.base64.Base64.encode("login:pasword"
                            .getBytes())));

    Object response = null;
    try {

        httpTransport.call(act, envelope, headerList);
        response = envelope.getResponse();

    } catch (Exception ex) {

        return ex.toString;

    }
    return ex.toString;
}
</code></pre>

<p>But I get the following Exception : </p>

<pre><code>org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG &lt;html&gt;@2:7 in java.io.InputStreamReader@44f66cb0)
</code></pre>
