How to use HttpWebRequest.Credentials Property for Basic Authentication?

后端 未结 3 1693
眼角桃花
眼角桃花 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:03

    I can successfull run this code accessing another server that also requires both SSL and authentication. This server differs from the github in that the github returns a json result saying that it requires authentication and the other server returns a "classic" 401 html page. Sniffing the network you can see that the .net code tries to do anonymous auth even if you do set preauth to true which I think is rather confusing. However, upon receiving a regular 401-page it tries again, and this time with the auth info and everything works. It seems to me though as if .net reacts differently upon receiving the json version of a 401, not making a second try.

    I guess this is not the answer you are looking for but hopefully it sheds some more light on the situation.

提交回复
热议问题