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;