1 Attachment(s)
[RESOLVED] WinHTTP 5.1 class wrapper
ORIGINAL TITLE: clsHttpRequests
I was searching for the proper class which supports HTTPS protocol and threading, and found this. It turned out that it's the best solution, but... I have realized that it doesn't support per-thread proxy and I need that for my project, so I contacted the author to send me the latest version. I have attached it to this post now (with simple test project included).
However, the function that I've mentioned above isn't implemented yet, and the class has timeout bug. The author said to me that currently he has no time to fix that, but he gave me some notes to do that by myself:
Quote:
Originally Posted by Cocus
Well, I've checked some info about the timeout issue. It seems to be a bug related to the InternetSetOption API. I should re-add the timers in the class to fire the timeout event. I'll do that eventually, but not right now. If you really need that, you can call CancelRequest with a VB timer.
Also the proxy stuff will be done, but not in the meantime, since I'm doing another projects not related to this one.
If you want to experiment, try to "copy" all the code from InitInternetConnection to SendRequest_OptionalAsByte, so each thread has its own "internet connection handle". After that, you can add another field in the "tThreadInfo" UDT, so the Internet Connection handle can be stored there and freed up when thread finishes (so you don't leak any handles). Also check for the "DestroyRemainingThreads", which also frees up handles.
Since I'm not expert in that field and I don't think that I'll ever succeed in making it possible, I want to ask if anyone here who is experienced enough is ready to try this challenge (I hope that it's not so hard), not only for me but also for the benefit of others who will eventually use it someday? Thanks in advance!
Re: [RESOLVED] clsHttpRequests
Oh, that didn't came into my mind. Thanks again!
Re: [RESOLVED] WinHTTP 5.1 class wrapper
If you read the documentation almost all of that is covered.
For example the .Status property has the status code and .StatusText has the raw response status text.
The .Send() method can have an optional parameter Body, and how it is treated depends on its type: String, Byte array, MSXML DOM object, or an object that implements the IStream interface such as the ADODB.Stream object.
Sending a normal VB "Unicode" String (BSTR) will send it encoded as UTF-8. The caller should set a Content-Type header with the appropriate content type and include a charset parameter. But you really should do this for any POSTed data.
In many ways this object parallels MSXML2.XMLHTTP, so IXMLHTTPRequest Members can be used as supplementary documentation to fill in the blanks you may find in the WinHttpRequest docs.
Re: [RESOLVED] WinHTTP 5.1 class wrapper
The need to configure multiple ("per thread") proxy servers made me suspicious that this might be intended for brute-force password cracking attempts hiding behind multiple "anonymizing" proxy servers in the dark parts of the Internet.
Otherwise it becomes difficult to imagine such a need.
Re: WinHTTP 5.1 class wrapper
I don't want to use this in web-scraping, I want to stress my web server and a service on it to see how it can/will handle requests from multiple IP addresses at the same time.
Last question: How to completely replace or clear cookies when I make another request on one/current instance? If I put command 'http.SetRequestHeader "Cookie", "test"', it won't work - it will add that to existing set of cookies. I have found this but I can't find a way to do that in VB6.
Re: WinHTTP 5.1 class wrapper
Have you tried using the WinHttpRequest's .Option property to set manual cookie handling?
Air code (untested):
Code:
'Values from Win 6.0 SDK header winhttp.h since the WinHttp typelib
'does not define them:
Const WinHttpRequestOption_DisableFeature As Long = 63
Enum WinHttpRequestOptionDisableFeature
DisableCookies = 1
DisableRedirects = 2
DisableAuthentication = 4
DisableKeepAlive = 8
End Enum
:
:
Req.Option(WinHttpRequestOption_DisableFeature) = DisableCookies
Once that is done, see Manually Specifying All Cookies in the page you linked.
Or perhaps simpler? Try to create a new instance of WinHttpRequest for every request?
Re: WinHTTP 5.1 class wrapper
Hm, It gives me an error "Invalid procedure call or argument".
I think that it's unnecessary to kill and then create a new instance for every request with same proxy address, that's why I'm asking if someone knows how to disable automatic cookie handling.
Re: WinHTTP 5.1 class wrapper
Then perhaps they are editing the range of properties or values and fail on anything they consider "unsafe." That might be why they only provide a limited set of predefined constants.
If you reject the idea of recreating instances for each request I'm out of suggestions.
1 Attachment(s)
Re: WinHTTP 5.1 class wrapper
I wanted to set some of already specified options but I've realized that I can't even do that - I get the same error that I've mentioned above ("Invalid procedure call or argument").
Attachment 123871
(I've put this before .Open command and I've tried setting with parameter "1", but again it won't work.)
It turns out that these are read-only options?! Does anybody know how can I solve this problem (or to tell me if that can't be done)?
Re: WinHTTP 5.1 class wrapper
The extended property WinHttpRequestOption_SslErrorIgnoreFlags is not Boolean. It takes bit-flag values from those spelled out in the Enum WinHttpRequestSslErrorFlags.
Re: WinHTTP 5.1 class wrapper
How to set that properly?
Edit: Found the parameter 13056 (to ignore all SSL errors) and it works, thanks!
Re: WinHTTP 5.1 class wrapper
Don't use a magic number, use the named value from the Enum I already showed you above.