How to use HttpWebRequest.Credentials Property for Basic Authentication?

后端 未结 3 1709
眼角桃花
眼角桃花 2020-12-18 08:33

How can I use the Webrequest Credentials Property to send an basic authentication header? Why isn\'t the Authorization header send with the request even when

3条回答
  •  眼角桃花
    2020-12-18 09:01

    The server should send a HTTP 401 Not Authorized response code containing a WWW-Authenticate HTTP header.

    WWW-Authenticate: Basic realm="example"
    

    The PreAuthenticate property only works after authentication has taken place. From MSDN:

    true to send an HTTP Authorization header with requests after authentication has taken place; otherwise, false. The default is false.

    See other answers for more in depth explanation.

提交回复
热议问题