Missing Basic HTTP authentication entry in HTTP request header

后端 未结 1 1649
失恋的感觉
失恋的感觉 2020-12-10 05:58

I have the following code:

WebClient client = new WebClient();
String un = \"Username\";
String pw = \"Password\";
client.Credentials =  new System.Net.Netwo         


        
相关标签:
1条回答
  • Try the old fashioned way:

    string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(un + ":" + pw));
    client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
    

    IIRC WebClient doesn't send the Authorization request header until it gets a challenge from the server with 401.

    0 讨论(0)
提交回复
热议问题