Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock Http Binary woes...

Status
Not open for further replies.

devilman0

IS-IT--Management
Nov 14, 2002
257
US
I found a sample app on the inet that will downloads a text file of the internet. I am trying to modify it to download binary information and save it to a file (an auto updater if you will). I have no intrest in using the inet control. I want to do this strictly with winsock componets. the code i have is below...
Code:
    If Not m_bHeaderReceived Then
        wscHttp.GetData strData, vbString
        m_strHttpResponse = m_strHttpResponse & strData
        intBreakePosition = InStr(1, m_strHttpResponse, vbCrLf & vbCrLf)
        If intBreakePosition Then
            m_bHeaderReceived = True
            m_lDownloadedBytes = m_lDownloadedBytes - intBreakePosition - 3
            vHeaders = Split(Left(m_strHttpResponse, intBreakePosition - 1), vbCrLf)
            For Each vHeader In vHeaders
                If InStr(1, vHeader, "Content-Length") Then
                    m_lContentLength = CLng(Mid(vHeader, InStr(1, vHeader, " ") + 1))
                End If
    '            If InStr(1, vHeader, "Content-Type") Then
    '                Select Case LCase(Mid(vHeader, InStr(1, vHeader, " ") + 1))
    '                    Case "text/html", "application/octet-stream", "text/plain"
    '                    ContentType = 0
    '                    Case "application/x-zip-compressed"
    '                    ContentType = -1
    '                    Case Else
    '                    ContentType = -2
    '                End Select
    '            End If
            Next
        End If
    Else
        wscHttp.GetData BytBuffer
        Debug.Print "recieved: " & bytesTotal & " Buffersize: " & (UBound(BytBuffer) + 1)
        Put #1, LPos, BytBuffer
        LTotalSize = LTotalSize + UBound(BytBuffer) + 1
        LPos = LPos + UBound(BytBuffer) + 1
        'm_strHttpResponse = m_strHttpResponse & strData
        'If m_lContentLength > 0 Then
            ProgressBar1.Value = m_lDownloadedBytes / (m_lContentLength / 100)
            StatusBar1.Panels(3).Text = "Downloaded " & m_lDownloadedBytes & _
                " from " & m_lContentLength & _
                " (" & CInt(m_lDownloadedBytes / (m_lContentLength / 100)) & "%)"
        'Else
        '    StatusBar1.Panels(3).Text = "Downloaded " & m_lDownloadedBytes & " bytes"
        'End If
    End If
that is the seciton of the code i am having problems with. when i download anything binary (images, exe's, etc) it gets corrupted (file size downloaded is smaller by a few kb than that of the org. Does any one have any thoughts as to what is going on? Thanks in advance.

Thanks,
James
[afro][mad]
"Make it idiot-proof and someone will make a better idiot." ~bumper sticker
 
Can you FTP the 'Get' the file??? if so there is a WinInet Bas module that should do the trick.

Microsoft has a MSDN on using the WinInet APIs for HTTP


also has an MSDN on using the WinInet Api for FTP


Hope this helps
[Cannon]

I can't program for the Unknown, I have A keyboard not a Ouija Board. (See an online ouija board at George Oakes
Check out this awsome .Net Resource!
 
Nope, ftp is out, i got it working tho. Thanks for your help

Thanks,
James
[afro][mad]
"Make it idiot-proof and someone will make a better idiot." ~bumper sticker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top