谁给个HttpWebRequest或者webclient获取https网页内容的代码! 如题。。求一个用上面类获取https网页内容的代码。只是确定功能无需导入证书等功能 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors){ //直接确认,否则打不开 return true;} private void button1_Click(object sender, EventArgs e){ ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); HttpWebRequest req = (HttpWebRequest)WebRequest.CreateDefault(new Uri("https://zu14.cn/")); req.Method = "GET"; HttpWebResponse res = (HttpWebResponse)req.GetResponse(); //正常使用了,和访问普通的 http:// 地址一样了} 楼上别直接抄袭CSDN上的啊。给个具体确实能用的例子。。包含调用的类 这例子还不够详细么?哪些类不明明白白写着要先登录的就用WebRequest模拟post方法,用myHttpWebRequest.CookieContainer.GetCookieHeader(myHttpWebRequest.RequestUri)得到对方set的cookie,然后带着这个cookie去访问需要登录才能访问的页面 这个方法,你可以直接调用!/// <summary>/// 获得页面的html代码/// </summary>/// <param name="url">页面地址</param>protected string getHtml(string url){ string html = ""; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Accept = "*/*"; HttpWebResponse response = null; Stream stream = null; StreamReader reader = null; try { response = (HttpWebResponse)request.GetResponse(); stream = response.GetResponseStream(); reader = new StreamReader(stream, Encoding.UTF8); html = reader.ReadToEnd(); } catch (Exception excpt) { } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (stream != null) { stream.Close(); stream.Dispose(); } if (response != null) { response.Close(); } } return html;} System.Net.WebClient wc = new System.Net.WebClient(); wc.Credentials = System.Net.CredentialCache.DefaultCredentials; Byte[] pageData = wc.DownloadData(""); string content= System.Text.Encoding.Default.GetString(pageData);System.Net.WebRequest request = System.Net.WebRequest.Create(""); System.Net.WebResponse response = request.GetResponse(); System.IO.Stream resStream = response.GetResponseStream(); System.IO.StreamReader sr = new System.IO.StreamReader(resStream, System.Text.Encoding.Default); string content= sr.ReadToEnd(); resStream.Close(); sr.Close(); 检测电脑是否连接投影设备 对已垃圾回收的委托进行了回调? 日期格式问题 C# 动态类型引用(求代码) IIS更新不了新发布的ASP.NET页面,怎么解决啊?[救命] 用XMLTextReader找出一篇XML文档的一个数字叶节点后,如何修改这个节点的数字??? 把分全给你,那为人兄给我发一份儿购物车的C#的源代码啊 c#全局静态数组锁定的问题 谁有FTP客户端下载程序的源代码。我有分相送。不够在加。 请问在TreeView中分级别加入节点的问题 想做一个投票表决系统,请求思路中! 有偿求助,C#高手请进
public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
//直接确认,否则打不开
return true;
}
private void button1_Click(object sender, EventArgs e)
{
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
HttpWebRequest req = (HttpWebRequest)WebRequest.CreateDefault(new Uri("https://zu14.cn/"));
req.Method = "GET";
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//正常使用了,和访问普通的 http:// 地址一样了
}
这例子还不够详细么?哪些类不明明白白写着要先登录的就用WebRequest模拟post方法,用myHttpWebRequest.CookieContainer.GetCookieHeader(myHttpWebRequest.RequestUri)得到对方set的cookie,然后带着这个cookie去访问需要登录才能访问的页面
/// 获得页面的html代码
/// </summary>
/// <param name="url">页面地址</param>
protected string getHtml(string url)
{
string html = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Accept = "*/*";
HttpWebResponse response = null;
Stream stream = null;
StreamReader reader = null;
try
{
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
reader = new StreamReader(stream, Encoding.UTF8);
html = reader.ReadToEnd();
}
catch (Exception excpt)
{
}
finally
{
if (reader != null)
{
reader.Close();
reader.Dispose();
}
if (stream != null)
{
stream.Close();
stream.Dispose();
}
if (response != null)
{
response.Close();
}
}
return html;
}
wc.Credentials = System.Net.CredentialCache.DefaultCredentials;
Byte[] pageData = wc.DownloadData("");
string content= System.Text.Encoding.Default.GetString(pageData);System.Net.WebRequest request = System.Net.WebRequest.Create("");
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream resStream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resStream, System.Text.Encoding.Default);
string content= sr.ReadToEnd();
resStream.Close();
sr.Close();