401 Unauthorized on SECOND HttpClient/HttpWebRequest call

后端 未结 3 1406
情书的邮戳
情书的邮戳 2021-01-15 02:32

I have a application that uses the SharePoint 2010 REST API. In the process of creating an Item there are multiple request done after each other:

1 Call:

相关标签:
3条回答
  • 2021-01-15 02:51

    Just run into the same problem.

    Anyway, the 2nd request does not follow the same authentication procedure. Even if you initialize a new HttpClient object. I sniffed the HTTP traffic. traffic

    After the 1st request I am doing another with different credentials. This is also ending in a 401. I am really confused...

    Seems the NTLM Handshake stucks at the 2nd of 6 steps http://www.innovation.ch/personal/ronald/ntlm.html

    Edit: You may want to use the CSOM. http://social.msdn.microsoft.com/Forums/office/en-US/efd12f11-cdb3-4b28-a9e0-32bfab71a419/windows-phone-81-sdk-for-sharepoint-csom?forum=sharepointdevelopment

    0 讨论(0)
  • 2021-01-15 02:53

    While I still don't know what the actual problem is, at least I found a workaround: Use the WebRequest class instead of HttpClient.

    0 讨论(0)
  • 2021-01-15 03:11

    I see that this question has been posted long back. But I don't see a correctly working solution posted yet to this thread.

    I faced exactly the same issue where the next requests kept on failing returning me 401 UnAuthorized.

    I figured out using fiddler that from SECOND request onwards, there was a Cookie added to the request which was possibly a result of Set-Cookie response sent by the server along with first response.

    So here's how I tackled the situation - Make UseCookies false:

    new HttpClientHandler { Credentials = myCred, UseCookies = false }
    

    This should resolve your issue. Hope this helps someone who's looking for a solution to a similar issue.

    0 讨论(0)
提交回复
热议问题