For ADSaunders: wininet/proxy

Ref.: my question "How to use proxy with wininet" in
http://www.experts-exchange.com/Community_Support/Expert_Input/Q_20742955.html

Initial sample can be downloaded from:
http://www.geocities.com/ameba_vb/temp/proxy.html

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)
       
    Else
        lHandle = InternetOpen(sAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    End If

Thanks
LVL 15
amebaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
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.


Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
amebaAuthor Commented:
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...
ADSaundersCommented:
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
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

TimCotteeHead of Software ServicesCommented:
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).
ADSaundersCommented:
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
amebaAuthor Commented:
ADSaunders,
> 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?
ADSaundersCommented:
Not as input, I'm in an NT authenticated domain.

.. Alan
amebaAuthor Commented:
I have updated sample with proxy username/password and Tim's correction.

Alan,
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.

Resend:
    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
        Case HTTP_STATUS_PROXY_AUTH_REQ
            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

Thanks!
ADSaundersCommented:
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winhttp/http/error_messages.asp is:

ERROR_WINHTTP_INVALID_SERVER_RESPONSE
12152
The server response could not be parsed.

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

.. Alan
ADSaundersCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amebaAuthor Commented:
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 http://www.mersenne.org/ips/faq.html#error_12152
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 proxy.supermegacorp.com, yet proxy13.supermegacorp.com replied, so you would use the latter"
ADSaundersCommented:
Hi,
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
amebaAuthor Commented:
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!
ADSaundersCommented:
ameba,
No Problem. And Thanks for the points.

.. Alan
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.