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

前端 未结 4 1595
误落风尘
误落风尘 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:04

    Try setting this:

    httpClientHandler.PreAuthenticate = true;
    

    I think the very first request will still get the initial 401, but subsequent request to the same URI up to the last forward slash should always send the authentication headers without the 401.

提交回复
热议问题