Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #1378

download an image using inet1.execute instead of .open

From David <rataxes@post.com>
Newsgroups comp.lang.basic.visual.misc
Subject download an image using inet1.execute instead of .open
Date 2012-07-18 15:13 -0700
Organization http://groups.google.com
Message-ID <a383d3c9-ca04-4207-ac7f-186b7ea18976@googlegroups.com> (permalink)

Show all headers | View raw


Hello VB ppl,

I'm writing a custom scraper tool that will fetch web data from a specific site.  Normally I would use the open method with internet transfer control but this specific site rejects http requests from the user agent associated with open.  If I use the execute method and custom user agent string I can get in.  The tool works fine for the text of the page, but now I want to tweak it to fetch images as well.  I'm having trouble figuring out how to populate my binary data variable to take in the stream produced by the control.  I've searched this group and other resources but I'm just more confused now.  Maybe someone can help me out.

The basic fetch code:

sub getImage()
  Inet1.Protocol = icHTTP
  Inet1.Execute URL, "GET", , "User-Agent: testing" & vbCrLf
  While Inet1.StillExecuting
    DoEvents
  Wend
end sub

Now if this was still text data I wanted I would use this:

Sub Inet1_StateChanged(ByVal state As Integer)
Dim data$, finalData$
    Select Case state
      Case 12 'icResponseCompleted
        data = Inet1.getChunk(4096)
        While data <> ""
          finalData = finalData & data
          data = Inet1.getChunk(4096)
        Wend
        'file write routine using finalData
...
end sub

But with binary data I'm getting type mismatch errors and such.  For one thing I don't know how to test whether the stream is done or not (as done above by testing if data="").  Nor do I know how to concatenate two binary variables or what the equivalent process would be if concatenate is the wrong concept.

Sub Inet1_StateChanged(ByVal state As Integer)
Dim data() As Byte, finalData() As Byte
  Select Case state
    Case 12 'icResponseCompleted
      data = Inet1.getChunk(1024, icByteArray)
      While data > 0
        finalData = finalData & data
        data = Inet1.getChunk(1024, icByteArray)
      Wend
      'file write routine using data().
...
  End Select
End Sub


Any ideas or suggestions?  I think once I get the data into the variable properly I can figure out how to write it out as a file.  Thanks for any assistance.

--David

Back to comp.lang.basic.visual.misc | Previous | NextNext in thread | Find similar | Unroll thread


Thread

download an image using inet1.execute instead of .open David <rataxes@post.com> - 2012-07-18 15:13 -0700
  Re: download an image using inet1.execute instead of .open Deanna Earley <dee.earley@icode.co.uk> - 2012-07-19 10:22 +0100
    Re: download an image using inet1.execute instead of .open "Theo Tress" <rbk@online.de> - 2012-07-25 18:44 +0200
      Re: download an image using inet1.execute instead of .open Deanna Earley <dee.earley@icode.co.uk> - 2012-07-26 10:21 +0100

csiph-web