Read Text File Content from HTTPS Web using VB6

53 Views Asked by At

I need source code for reading the .txt content from a HTTPS URL. I have the one that successfully reads from a HTTP website, but i am having issues since my host forced HTTPS protocols on all URL.

The source code i use for HTTPS is :

Private Function GetHttpText(ByVal URL As String) As ADODB.Stream
    Dim Req As MSXML2.XMLHTTP
    Dim CharSet As String
    Dim CharsetPos As Long
    Dim LineSeparator As LineSeparatorEnum

    Set Req = New MSXML2.XMLHTTP
    Set GetHttpText = New ADODB.Stream
    With GetHttpText
        .Open
        .Type = adTypeBinary
        With Req
            .Open "GET", URL, False
            .send
            CharSet = LCase$(.getResponseHeader("CONTENT-TYPE"))
        End With
        .Write Req.responseBody
        CharsetPos = InStr(CharSet, "charset")
        If CharsetPos Then
            CharSet = Split(Mid$(CharSet, CharsetPos), "=")(1)
        Else
            'UTF-8 is a reasonable "default" these days:
            CharSet = "utf-8"
        End If
        If CharSet = "utf-8" Then
            LineSeparator = adLF
        Else
            'Your milage may vary here, since there is no line-end
            'header defined for HTTP:
            LineSeparator = adCRLF
        End If
        .Position = 0
        .Type = adTypeText
        .CharSet = CharSet
        .LineSeparator = LineSeparator
    End With
End Function

Private Sub DumpTextLineByLine()
    With GetHttpText("http://textfiles.com/art/simpsons.txt")
        'Read text line by line to populate a multiline TextBox
        'just as a demonstration:
        Do Until .EOS
            Text1.SelText = .ReadText(adReadLine)
            Text1.SelText = vbNewLine
        Loop
        .Close
    End With
End Sub

Above source code is courtesy @Bob77 But if i run the above for HTTPS website, i get the error of "Error Occurred in the Secure Channel Support" Please help with a source code that can read successfully from HTTPS web.

0

There are 0 best solutions below