HttpClient fails to authenticate via NTLM on the second request when using the Sharepoint REST API on Windows Phone 8.1 -



HttpClient fails to authenticate via NTLM on the second request when using the Sharepoint REST API on Windows Phone 8.1 -

sorry long title, seems best summary based on know far.

we’re working on universal app needs access documents on sharepoint server via rest api using ntlm authentication, proves more hard should be. while able find workarounds problems (see below), don’t understand happening , why necessary. somehow httpclient class seems behave differently on phone , on pc. here’s figured out far.

i started code:

var credentials = new networkcredential(username, password); var handler = new httpclienthandler() { credentials = credentials }; var client = new httpclient(handler); var response = await client.getasync(url);

this works fine in windows app, fails in windows phone app. server returns 401 unauthorized status code.

some research revealed need provide domain networkcredential class.

var credentials = new networkcredential(username, password, domain);

this works on both platforms. why domain not required on windows?

the next problem appears when seek multiple requests:

var response1 = await client.getasync(url); var response2 = await client.getasync(url);

again, works fine in windows app. both requests homecoming successfully:

and again, fails on phone. first request returns without problems:

strangely consecutive requests same resource fail, 1 time again status code 401.

this problem has been encountered before, there doesn’t seem solution yet.

an reply in sec thread suggests there’s wrong ntlm handshake. why sec time? also, seems problem of httpclient class, because next code works without problems on both platforms:

var request3 = webrequest.createhttp(url); request3.credentials = credentials; var response3 = await request3.getresponseasync(); var request4 = webrequest.createhttp(url); request4.credentials = credentials; var response4 = await request4.getresponseasync();

so problem appears:

on windows phone. same code in windows app works. when connecting sharepoint. accessing site ntlm authentication works on both platforms. when using httpclient. using webrequest, works.

so while i'm glad @ to the lowest degree found way create work, i’d know what’s special combination , done create work?

hi daniel @ same problem when sync, because windows phone had lot of problems cache, finallt solve add together headers. think it's thought utilize timeout because it's loooong response can wait lot of time... , other way work it's utilize "using", it's similar utilize ".dispose()". show code:

var request3 = webrequest.createhttp(url); request3.credentials = credentials; request.continuetimeout = 4000; //4 seconds //for solve cache problems request.headers["cache-control"] = "no-cache"; request.headers["pragma"] = "no-cache"; using(httpwebresponse response3 = (httpwebresponse) await request3.getresponseasync()){ if (response3.statuscode == httpstatuscode.ok) { //your code... } } var request4 = webrequest.createhttp(url); request4.credentials = credentials; request.continuetimeout = 4000; //4 seconds //for solve cache problems request.headers["cache-control"] = "no-cache"; request.headers["pragma"] = "no-cache"; using(httpwebresponse response4 = (httpwebresponse) await request4.getresponseasync()){ if (response4.statuscode == httpstatuscode.ok) { //your code... } }

i wait code can help you. , luck!

sharepoint windows-phone-8.1 ntlm dotnet-httpclient win-universal-app

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -