如题。。求一个用上面类获取https网页内容的代码。只是确定功能无需导入证书等功能

解决方案 »

  1.   


    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:// 地址一样了
    }
      

  2.   

    楼上别直接抄袭CSDN上的啊。给个具体确实能用的例子。。包含调用的类
      

  3.   


    这例子还不够详细么?哪些类不明明白白写着要先登录的就用WebRequest模拟post方法,用myHttpWebRequest.CookieContainer.GetCookieHeader(myHttpWebRequest.RequestUri)得到对方set的cookie,然后带着这个cookie去访问需要登录才能访问的页面
      

  4.   

    这个方法,你可以直接调用!/// <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;
    }
      

  5.   

    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();