HttpClient in .net issues 2 requests when providing username and password in NetworkCredentials

前端 未结 4 1561
误落风尘
误落风尘 2021-01-18 08:00

When using the HttpClient in .net 4.5 to do basic authentication I\'m finding that it\'s issuing 2 requests.

The first fails with a HTTP/1.1 401 Unauthorized and the

4条回答
  •  感情败类
    2021-01-18 08:09

    While looking for an answer to another problem I have with the NetworkCredentials I stumbled across two questions with answers that might be the ones you're looking for:

    Here the answer says that at least WebRequest has the default behaviour of only sending the credentials after getting a 401. And here it seems that the solution might be using a CredentialCache.

    I'm not sure if the CredentialCache works with the HttpClient, but if it doesn't you could switch to WebRequest or also WebClient, or maybe this information just brought you on the path to another solution.

提交回复
热议问题