401 Unauthorized on SECOND HttpClient/HttpWebRequest call

后端 未结 3 1405
情书的邮戳
情书的邮戳 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 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.

提交回复
热议问题