标签:
private void btnopenURL_Click(object sender, EventArgs e)
{
string strUrl = txtopenURL.Text.Trim();
// webBrowser1.Navigate(strUrl);
//ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);//验证服务器证书回调自动验证
//创建http链接
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl);
/**
request.Credentials = CredentialCache.DefaultCredentials;
request.Credentials = new NetworkCredential("user", "密码", strUrl);
**/
string username = "user";
string password = "二次密码";//注意这里的格式哦,为 "username:password"
string usernamePassword = username + ":" + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(strUrl), "Basic", new NetworkCredential(username, password));
request.Credentials = mycache;
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//构造数据流对象实例
WebResponse stream = request.GetResponse();
Stream receiveStream = stream.GetResponseStream(); //GetResponseStream:获取应答流
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);//从字节流中读取字符
string content = reader.ReadToEnd(); //从流当前位置读取到末尾并显示在WebBrower控件中
webBrowser1.DocumentText = content;
}
标签:
原文地址:http://www.cnblogs.com/alex-13/p/4844854.html