0

I've got a problem with authentication while connecting to web service. When I tried to open it by web browser it asked me to log in with "login" and "password". I am using the code below to authenticate, but it doesn't work. I am getting 401. I tried everything I've found, but I still can't connect.

String res = "sample string";
        SoapObject request = new SoapObject(NAMESPACE, METHODNAME);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(WSDL);

        List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
        headers.add(new HeaderProperty("Authorization", "Basic " + org.kobjects.base64.Base64.encode("my_username:my_password".getBytes())));

        androidHttpTransport.debug = true;


        try {

            androidHttpTransport.call(SOAP_ACTION, envelope, headers);
            SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
            res = resultsRequestSOAP.toString();


            System.out.println("Response: " + resultsRequestSOAP.toString());

        } catch (Exception e) {  //here comes org.ksoap2.transport.HttpResponseException: HTTP request failed, HTTP status: 401
            Log.d(TAG, e.getMessage());
        }
        return res;
SkypeDogg
  • 1,000
  • 2
  • 13
  • 28

1 Answers1

0

If someone is watching this question, I was able to get logs from the server, and here's what I've got:

2018-11-30 13:13:36 YY.YY.YY.YY POST /MicrosoftDynamicsAXAif50/servicee.svc - 89 - XX.XX.XX.XX ksoap2-android/2.6.0+ - 401 2 5 15

YY - server address, XX - mine
Before my address should be my username, and there shouldn't be lib name as you can see. How can I make it work? Because I will always get rejected by server with this.

SkypeDogg
  • 1,000
  • 2
  • 13
  • 28