访问需要HTTP Basic Authentication认证的资源的c#的实现 将账号密码放入url

string url = "";

string usernamePassword = username + ":" + password;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
myReq.Credentials = new NetworkCredential(username, password);
//CredentialCache mycache = new CredentialCache();
//mycache.Add(new Uri(url), "Basic", new NetworkCredential());
// myReq.Credentials = mycache;
//myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword))); //HttpWebResponse b = (HttpWebResponse)myReq.GetResponse();
//Stream stream = b.GetResponseStream();
//StreamReader content = new StreamReader(stream); WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
textBox1.Text = content + "\r\n" + textBox1.Text;
上一篇:访问需要HTTP Basic Authentication认证的资源的各种开发语言的实现


下一篇:HTTP Basic Authentication认证的各种语言 后台用的