本文介绍了使用C#中的asp.net对HTTPS上任何站点的安全页面进行屏幕抓取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图通过下面的代码来抓取HTTPS站点的安全页面,但是我无法抓取该安全.登录页面被抓取.

这是类文件的代码:

Hi,

I''ve tried to scrape a secure page of a HTTPS Site by below code but I''m not be able to scrape the secure. The login page is scraped.

This is code of class file:

using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

/// <summary>
/// Summary description for CertificateOverride
/// </summary>
public class CertificateOverride : ICertificatePolicy
{
    public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
    {
        return true;
    }
    

 public bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
 {
    return true;
 }

//And the code of method where I scraped the site is:
public void ScrapePage()
    {
       //-- over ride the bad certificate error
        ServicePointManager.CertificatePolicy = new CertificateOverride();
       
        WebRequest request =
           HttpWebRequest.Create(
              "Login URL");
        NetworkCredential credential= new NetworkCredential("LoginID", "Password");
        request.Credentials = credential;
        WebResponse response = request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string str = reader.ReadToEnd();
        Response.Write(str);
       
    }
}


请告知,我写代码做错了什么?

谢谢
Ajit Gupta


Please advise,what mistake have i done to write the code?

Thanks
Ajit Gupta

推荐答案


这篇关于使用C#中的asp.net对HTTPS上任何站点的安全页面进行屏幕抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:59