For ADSaunders: wininet/proxy

ameba used Ask the Experts™
Ref.: my question "How to use proxy with wininet" in

Initial sample can be downloaded from:

I'll try to add code for proxy username/password, and it seems even PORT doesn't have a place in my 'sample'

    If bUseProxy Then
        ' ??? I cannot TEST this part, and I don't know where to put PROXY PORT
        lHandle = InternetOpen(sAgent, INTERNET_OPEN_TYPE_PROXY, ProxyAddress, "", 0)
        lHandle = InternetOpen(sAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    End If

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
TimCotteeHead of Software Services

Hi ameba,

Just read this and the original reason, I have tested it with ISA server here and made this change to get it to use the appropriate port:

        lHandle = InternetOpen(sAgent, INTERNET_OPEN_TYPE_PROXY, ProxyAddress & ":" & ProxyPort, "", 0)

Seems to work fine this way.

Brainbench MVP for Visual Basic


Great, thanks!
See "points for" http:Q_20821947.html

I'll update the sample, and try to find another code for proxy username/password. I'm looking at one, but seems it requires two visits...
Hi ameba,
I've tried your code, and it's failing at the sendrequest call in the getUrl sub.
Curiously, your sample works for me if I don't check 'use proxy'.

I have proved that it is ISA causing the problem, as I have reconfigured my TCP/IP to bypass it and Quickpost works ok. (can't leave it like that though!)

.. Alan
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

TimCotteeHead of Software Services

Alan, how did you reconfigure to bypass ISA? I have to use our US gateway to get QP working as the ISA is blocking it for some reason (even though I have administrative rights to the ISA server I cannot change it unfortunately).
Disabled MS Firewall client, set Explorer connection to no proxy, and set TCP/IP default gateway to the trusted IP of the hardware firewall.

.. Alan


> Curiously, your sample works for me if I don't check 'use proxy'.

Well, the sample was extracted from new version of QP, which is a bit different - old version uses InternetOpenUrl, new (unpublished) QP uses HttpOpenRequest / HttpSendRequest combination.
I made that change because authorization for Jan Development server didn't work.

> I've tried your code, and it's failing at the sendrequest call in the getUrl sub.

Does your proxy require Username/Password?
Not as input, I'm in an NT authenticated domain.

.. Alan


I have updated sample with proxy username/password and Tim's correction.

if HttpSendRequest failed, it should return some error code. "HttpSendRequest call failed; Error code: ......."
I'm not sure, if it will work to that point, but in the new sample there is also  dwStatus returned by HttpQueryInfo. What is its value?
Note: you'll have to comment out line:
    If bUseProxy And Len(ProxyUsername) > 0 Then
and its "End If", to reach HttpQueryInfo.

    ret = HttpSendRequest(hUrl, "", 0, "", 0&)
    If ret = 0 Then Err.Raise vbObjectError + 1000, , "HttpSendRequest call failed; Error code: " & Err.LastDllError & "."

'    If bUseProxy And Len(ProxyUsername) > 0 Then
        ' proxy authorization
        Dim dwStatus As Long, dwStatusSize As Long
        dwStatusSize = Len(dwStatus)
        HttpQueryInfo hUrl, HTTP_QUERY_FLAG_NUMBER Or HTTP_QUERY_STATUS_CODE, dwStatus, dwStatusSize, 0
        Select Case dwStatus
            ret = InternetSetOptionStr(hUrl, INTERNET_OPTION_PROXY_USERNAME, _
                ProxyUsername, Len(ProxyUsername) + 1)
            ret = InternetSetOptionStr(hUrl, INTERNET_OPTION_PROXY_PASSWORD, _
                ProxyPassword, Len(ProxyPassword) + 1)
            GoTo Resend
        End Select
'    End If

Hi ameba,
(I thought I'd already answered this, if so, it's posted against the wrong question!)
Yes, I made a note of the DLLError,
 it was 12152 which according to is:

The server response could not be parsed.

I'll get a look at your new code later.

.. Alan
Well, ameba,

I checked your new sample, and here are my results:
1. No proxy set (all fields blank, 'use proxy' unset) .... OK
2. Use proxy set, remaining fields blank .. Error 12002 - expected, use proxy but no proxy defined
3. use proxy set, proxy server set but no port, username or password .. error 12152 (obviously that's due to the missing port number)
4. use proxy set, proxy server and port set but no username or password .. OK dwStatus = 200 (commented code as above)
5. All set ... OK dwStatus = 200
6 All set, but with rubbish in the Username and password .. OK dwStatus = 200
7. As 1 but with code commented .. Error 12002

Which brings me to a thought ... (should this be in the prior thread??)
In Quickpost, when I open a folder in my topics, it is able to read the questions OK. The question list appears, and the first question is opened and displayed. It is only when I click on another question, that I get 'Invalid Question' following through to a hang, or attempt to use the timed check facility. Question ... What is different in the code between opening the first question when opening a folder, and opening a question when clicked on?

.. Alan


Hi Alan,

Thanks again for debugging this.

> What is different in the code between opening the first question
> when opening a folder, and opening a question when clicked on?

When you click question, it will be reloaded, i.e. Reload flag is added, the same as pressing Shift+Refresh in browser.
When selecting folder, or using Back button, question is retrieved *without* Reload flag.  That seems to work, i.e. the problem is only when 'fresh' version is forced with Reload flag.
Also described in qp thread in post 114, http:Q_20742955.html#9772786.

Please, make Reload checkbox checked, and uncheck Use Proxy - does it still work in that 'automatic' mode?

For error 1252 I found some info at
and it is possible that specified address is not the "real" one, but there is some kind of proxy redirection.  It mentions workaround, but that is too complicated (to be used in qp), it's using ping to manually resolve address:
"If the ping command echos back from a different proxy server name, use that name instead in the primenet.ini file. In the example above, we pinged, yet replied, so you would use the latter"
Sorry for the delay, our ISP couldn't seem to resolve DNS for a while.

Yes, with just the reload flag set (no others except question no.), it retrieved the page.
with use proxy set, proxy host ands port set as well, (code commented) retrieved page ok, dwStatus is still 200.

.. Alan


OK. That looks OK.  Hope it will also work for submitting.  I'll update QP and upload new version tomorrow and we'll see.

Thanks for your help!
No Problem. And Thanks for the points.

.. Alan

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial