Welcome to CrankyGoblin.Com Sign in | Join | Help

Public Class GeoffAppleby

Inherits Microsoft.VisualBasic.MVP : Implements IBrainFart
The first annual "Geoff's too lazy to code" competition.

Hello.

Do you get sick and tired of chasing GMail accounts? Once you get one, then all your friends want one, and of course, you never actually get any invites for yourself?

Do you get sick and tired of writing all that boring, easy, powerful, .net code in the language of your choice? Do you miss the good old days of C++ or VB6?

Well have i got a deal for you!

I've got 6 invites to give away. Yes, that's right, 6!

What's the catch? No catch. I will give one person all 6 invites. That's right! Just contact me with your list of six names and addresses to send them to, and I will personally send them out!

Ok, so there IS a catch.

It's too easy just to give them away one at a time. I just want to get rid of them. So someone can have all 6. But you have to prove your worthiness.

So I thought of this competition. I want a decent coder to inherit this lucky prize. So here's the scoop.

Write for me some that does the following:

a) Receives a http URL as an input.

2) Returns a string as an output.

iii) The string stated in 2) is to be the content of the file downloaded in a).

The trick here is that it:

i) Automatically discovers if a proxy host is in use (this includes all options via setting it in IE - specific host, auto detect, a proxy.pac file, or none) and retrieves it successfully using the correct proxy.

b) It MUST be either COM or standard Win32 callable. That is, I want to be able to call it from VB6 - there is NO .net framework allowed!

3) I just want the source. To do the actual retrieval, using some other object like XMLHttp, ServerXMLHttp, or somethign built in to windows or VB6 is ok. But you MUST be able to work out the proxy.

Any takers? Go on, show me what you can do!

If you can't do it, but can find me a free/cheap third party solution or source example, then I might consider that a good enough entry. In fact, i'll probably kiss your dog, because i can't find anything good enough.

Let the games begin!

Edit: Seems I forgot something important. It has to be windowless. No embedded invisible IE's allowed, because there is no way of reliably intercepting all popups that IE could throw up (and believe me, i know!)

Listening to: disenchanted lullaby - foo fighters - (4:35)
Posted: Tuesday, 31 August 2004 5:36 PM by Geoff Appleby

Comments

Fred said:

Why don't you just embed an IE browser object in your form? You could just force it to invisible and grab the HTML content. From my experience, the embedded IE component always uses the same settings as the user's IE. Are there problems with that method I'm missing? I can't mock up the code myself, because I only have C# installed, but I've done it before, in Delphi. I'm positive it worked in VB6 too.
# September 1, 2004 6:41 AM

Geoff Appleby said:

A good point, except for a peice of information i forgot to give. See my edits for details.

Nice try, however! :)
# September 1, 2004 6:54 AM

Fred said:

I can't see an easy way around that without detecting and parsing the proxy.pac or wpad.dat yourself, but you DID ask previously for a way to tell if the "autodetect" box was ticked in IE - I've found it on XP, though whether it's portable across all Windows/IE versions I'm not sure.

In HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections, value DefaultConnectionSettings, byte 8 (starting from 0 as in Regedit), bit 3 seems to toggle this setting. i.e: on my system, that byte is set to 1 - if I set it to 9 instead, autodetect is turned on.
# September 1, 2004 8:19 AM

Fred said:

Oh, one more thing - you may not like embedding an IE-style control in your code for general use, but you COULD embed it there for the sole purpose of parsing the proxy.pac for you - if you point the browser at that file, the contents will say something like "PROXY: we.hate.our.users:8080". In theory, you shouldn't see any popup errors from that one file, and it would save you the trouble of building your own parser. I think you'd have to generate a small page that included proxy.pac and called the function directly with your desired URL though.
# September 1, 2004 8:22 AM

Geoff Appleby said:

Fred, thanks for your input.

Using an IE window is really a last resort for me. I can certianly use it if I have to, and believe me, i'm an expert at using it (all false modesty aside).

Parsing the pac file yourself is nto pleasant - it's not jsut a case of searching for the PROXY line - the one here at my work, for example, contains many different switches providing a set of 10 different proxies, witha specific one to be used depending on the location of the url to be retrieved.

I've so far dug up three key peices of information that have been of assistance for me. In wininet.dll there's a function you can call that will give you nice information about proxy usage - it returns a struct that tells you if auto-detect is ticked, if a pac file has been explicitly set (and what it's location is), and if any explicit proxy host has been named. FindProxy() or something similar is what

Using WinHTTP 5.1 you can call methods on it to tell you what proxy you need to use for any given URL, it automatically works it out for you.

In wininet, there's the same deal, but you have to call LoadLibrary() on JSProxy.dll yourself, and then request function pointers for the calls you want to make - you can't link against it at compile time.

I can't, unfortunately, use winhttp as i need to target win98 boxes. And i've been delaying writing it myself because i've got better things to do :)

So i thought i'd see if anyone was up for the challenge!
# September 1, 2004 9:16 AM

Andrew Taylor said:

Use the WININET.LIB library. It's a library of C calls for doing HTTP and FTP that comes with all versions of windows >= 95. Call InternetOpen with INTERNET_OPEN_TYPE_PRECONFIG to use IE proxy settings. Here is the code, sans error checking, etc:

#include <wininet.h>

HINTERNET inet = InternetOpen("myUserAgent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

HINTERNET hconn = InternetConnect(inet, hostname, INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);

HINTERNET hreq = HttpOpenRequest(hconn, "GET", path, NULL, NULL, NULL, INTERNET_FLAG_NO_UI, 0);

while (InternetReadFile(hreq, buffer, sizeof(buffer), &dwRead)) {
if (dwRead == 0)
break;
fwrite(buffer, 1, dwRead, someFile);
}

InternetCloseHandle(hreq);
InternetCloseHandle(hconn);
InternetCloseHandle(inet);

Easy as that!
# September 2, 2004 1:30 AM

Geoff Appleby said:

Hmmm...it cant' be as easy as this can it?

I could have sworn that when i looked into it the INTERNET_OPEN_TYPE_PRECONFIG ignored autodetect/proxy.pac files.

I'm going to run this to see how it goes, and if it works, then i get a smack on the head and you get 6 gmail invites. Thanks! :)
# September 2, 2004 1:37 AM

Geoff Appleby said:

OK, smack me on the head now :)

Your code didn't work, but only because you forgot the HttpSendRequest() call after the HttpOpenRequest() method.

I'm stuffed if i know why i thought these standard calls didn't support auto config files, but I can't say i care, just so long as it works.

Congrats to Andrew Taylor for the assist, i'll be contacting you soon with regards to your prize.

:)
# September 2, 2004 3:44 AM

An attempt at structured thought. said:

And the competition, so quickly, comes to an end.
# September 1, 2004 2:43 PM

James Manning said:

Make sure to check out Joe Stegman's recent demos on channel9, one of them is at:

http://channel9.msdn.com/ShowPost.aspx?PostID=21658
# September 11, 2004 10:36 PM

Preston said:

I still want to see the pic of you kissing his dog :)
# January 19, 2005 10:40 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

To submit your comment, click on these pictures:
  • Sleepy Geoff
  • Geoff's pretty blue eyes
  • Hairy Geoff
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Can't recognise the people in these pictures? Look here for a quick introduction.
There's a time limit for you to get your comment submitted before this set of pictures expires. If you think it's been longer than 10 minutes, get some new pictures first (you won't lose what you've typed so far).
Get some new pictures 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS