Link to home
Start Free TrialLog in
Avatar of ameba
amebaFlag for Croatia

asked on

For ADSaunders: wininet/proxy

Ref.: my question "How to use proxy with wininet" in
https://www.experts-exchange.com/questions/20742955/QuickPost-bug-reports-and-feedback.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
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of ameba

ASKER

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...
Avatar of ADSaunders
ADSaunders

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
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
Avatar of ameba

ASKER

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?
Not as input, I'm in an NT authenticated domain.

.. Alan
Avatar of ameba

ASKER

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!
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
ASKER CERTIFIED SOLUTION
Avatar of ADSaunders
ADSaunders

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ameba

ASKER

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"
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
Avatar of ameba

ASKER

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!
ameba,
No Problem. And Thanks for the points.

.. Alan