Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.Net WebClient DownloadString无法处理混合内容_.net_Vb.net_Https_Webclient_Mixed Content - Fatal编程技术网

.Net WebClient DownloadString无法处理混合内容

.Net WebClient DownloadString无法处理混合内容,.net,vb.net,https,webclient,mixed-content,.net,Vb.net,Https,Webclient,Mixed Content,我正在使用scraper,在其中我需要从一个站点上刮取数据。我已经厌倦了使用非常简单的webclient downloadString来获取数据,这似乎与其他站点一起工作,但我在下面的代码中尝试了一个问题。任何帮助都将不胜感激。提前谢谢。下面是VB.Net中的代码,但我也很高兴有一个c#的工作解决方案 在使用.DownloadString()方法之前,必须为此网站添加用户代理 在使用.DownloadString()方法之前,必须为此网站添加用户代理 你能就你的问题提供更多的信息吗。你想干什么?

我正在使用scraper,在其中我需要从一个站点上刮取数据。我已经厌倦了使用非常简单的webclient downloadString来获取数据,这似乎与其他站点一起工作,但我在下面的代码中尝试了一个问题。任何帮助都将不胜感激。提前谢谢。下面是VB.Net中的代码,但我也很高兴有一个c#的工作解决方案


在使用.DownloadString()方法之前,必须为此网站添加用户代理


在使用.DownloadString()方法之前,必须为此网站添加用户代理


你能就你的问题提供更多的信息吗。你想干什么?如果其他站点正常工作,那么这个站点有什么错误?@Youssed13已经解决了我的问题。请核对他的答案。谢谢你给我时间回答我的问题。你能为你的问题提供更多的信息吗。你想干什么?如果其他站点正常工作,那么这个站点有什么错误?@Youssed13已经解决了我的问题。请核对他的答案。谢谢你给我时间回答我的问题。谢谢,你救了我一天。谢谢,你救了我一天。
Private Function GetHtml() As String
    Dim mData As String = ""
    Try
        'ServicePointManager.ServerCertificateValidationCallback = New Security.RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)
        'ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

        With mWC
            mData = .DownloadString("https://www.adorama.com/brands")
        End With
    Catch ex As Exception
        Debug.Print(ex.Message)

        'With CertificateValidationCallback
        'The remote server returned an error: (403) Forbidden.

        'Without CertificateValidationCallback
        'The request was aborted: Could not create SSL/TLS secure channel.
    End Try

    Return mData
End Function

Private Shared Function ValidateServerCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As Net.Security.SslPolicyErrors) As Boolean
    If sslPolicyErrors = Net.Security.SslPolicyErrors.None Then
        Return True
    End If

    Return True
End Function
mWC.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")