problem with getting html page code into text field

Viewed 25

There is the following code to get the html code from a specific page:

 Private Shared Function ReadsourceCode(ByVal Url As String) As String

        ServicePointManager.ServerCertificateValidationCallback = Function()
                                                                      Return True
                                                                  End Function
        Dim data As String = ""
        Dim request As HttpWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)
        Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

        If response.StatusCode = HttpStatusCode.OK Then
            Dim receiveStream As Stream = response.GetResponseStream()
            Dim readStream As StreamReader = Nothing

            If response.CharacterSet Is Nothing Then
                readStream = New StreamReader(receiveStream)
            Else
                readStream = New StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet))
            End If

            data = readStream.ReadToEnd()

            response.Close()
            readStream.Close()
        End If
        Return data
    End Function

TextBox1.Text = ReadsourceCode(url)

The problem is that when executing this code, the following error pops up:

System.Net.WebException: "The underlying connection was closed: An unexpected error occurred while transmitting."

IOException: Authentication failed because the transport stream was closed by the remote side.

I assume that the problem is with the certificate. Is it possible to bypass it somehow?

0 Answers
Related