Pre-emptive basic HTTP authentication
nicolabeghin opened this issue · 2 comments
nicolabeghin commented
Hi everyone
does anyone know how to get pre-emptive Basic HTTP authentication working with SimpleSOAPClient?
If it's not supported explicitly, it should be enough to wrangle the HTTP headers, adding "Authorization: base64encode(user:password)".
Having access to the underlying HttpClient, it should be a matter of
HttpClient client = new HttpClient(handler);
var byteArray = Encoding.ASCII.GetBytes("username:password1234");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
thanks
nicola
nicolabeghin commented
Found it, closing the issue!
string clearTextCredentials = string.Format("{0}:{1}", SAP_USERNAME, SAP_PASSWORD);
client.HttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(clearTextCredentials)));
gravity00 commented
You could also add an ISoapHandler
to the client and before each request, using the OnHttpRequest
event, assign the header to the HttpRequestMessage
(property OnHttpRequestArguments.Request
).