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


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

Re: download an image using inet1.execute instead of .open

From Deanna Earley <dee.earley@icode.co.uk>
Newsgroups comp.lang.basic.visual.misc
Subject Re: download an image using inet1.execute instead of .open
Date 2012-07-19 10:22 +0100
Organization Aioe.org NNTP Server
Message-ID <ju8jl4$ptl$1@speranza.aioe.org> (permalink)
References <a383d3c9-ca04-4207-ac7f-186b7ea18976@googlegroups.com>

Show all headers | View raw


On 18/07/2012 23:13, David wrote:
> 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:
>
<SNIP>
>
> 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.
>
<SNIP>
>
> 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.

VB6 doesn't allow you to just append to an array.

Your best bet is to create a large byte array (to fit the image you 
expect), and then CopyMemory() each chunk into that point of your final 
buffer.
You can check the size to see if the new buffer will fit first then 
extend it (Redim Preserve) by a reasonable amount if needed.
When it's finished, you know how much you've received and then truncate 
the array (Redim Preserve again).

-- 
Deanna Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the 
group.)

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next 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