I am using 'InternetOpen' and have found that the 'INTERNET_OPEN_TYPE_PRECONFIG'
flag doesn't seem to work properly - I can use 'HttpSendRequest' once and then
it fails on the second time. So instead of using 'INTERNET_OPEN_TYPE_PRECONFIG' I
am trying to simulate it's behaviour using 'INTERNET_OPEN_TYPE_PROXY'
or 'INTERNET_OPEN_TYPE_DIRECT'. Ideally I want my app to do as IE does.
Basically I am checking whether a proxy is being used 'IsNetConnectViaProxy()', if
it isn't then I use the 'INTERNET_OPEN_TYPE_DIRECT' flag and if a proxy is used I
use the 'INTERNET_OPEN_TYPE_PROXY' flag and set-up the proxy list and proxy bypass
list. When I set the proxy list in 'OpenInternet' it seems to work and when I set
the proxy bypass list explicitly to a particular server name then it seems to work
as well. However, the doco says I should be able to set the proxy bypass to
'<local>' to avoid intranet sites going through the proxy (same as setting
'Bypass proxy server for local (Intranet) addresses' in IE). This doesn't seem to
have any effect as I'm still getting asked for proxy authenication on intranet
addresses and wondered if anyone out there had any success with this particular
arrangement.
Another related issue... I've written a routine to extract the proxy config info
called 'GetProxyInfo()' that I will eventually pass into 'InternetOpen'. The MS
doco says not to use the registry values directly but use 'InternetQueryOption' as
I have done. My routine returns the value 'www-proxy:8080' for the proxy and
'www-proxy:8080 <local>' for the bypass list. If I look at the registry the proxy
name is the same as expected but the bypass list reads just ';<local>' as I'd
expect. Any idea why I'm getting xtra data back - the 'www-proxy:8080' is
unexpected? I've included my code at the end.
WinInet is causing me no end of troubles so I'd appreciate any advice.
Thanks,
Jonathan.
________________________________________________________________________________
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (lpdwFlags As
Long, ByVal dwReserved As Long) As Boolean
Private Declare Function InternetQueryOption Lib "wininet.dll" Alias
"InternetQueryOptionA" (ByVal hInternet As Long, ByVal dwOption As Long, lpBuffer
As Any, lpdwBufferLength As Long) As Boolean
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA"
(ByVal lpszAgent As String, ByVal dwAccessType As Long, ByVal lpszProxyName As
String, ByVal lpszProxyBypass As String, ByVal dwflags As Long) As Long
Private Type INTERNET_PROXY_INFO
dwAccessType As Long
lpszProxy As Long 'proxy server list
lpszProxyBypass As Long 'proxy bypass list
End Type
Public Function IsNetConnectViaProxy() As Boolean
Dim dwflags As Long
InternetGetConnectedState dwflags, 0&
'return True if the flags indicate a proxy connection
IsNetConnectViaProxy = dwflags And INTERNET_CONNECTION_PROXY
End Function
Public Sub GetProxyInfo()
Dim uIPI As INTERNET_PROXY_INFO
Dim lSize As Long
Dim bytBuffer() As Byte
Dim sTemp As String
Dim sProxy As String
Dim sProxyBypass As String
Dim lPos As Long
Debug.Print InternetQueryOption(0&, INTERNET_OPTION_PROXY, ByVal 0&, lSize)
Debug.Print "Size:"; lSize
ReDim bytBuffer(1 To lSize)
Debug.Print InternetQueryOption(0&, INTERNET_OPTION_PROXY, bytBuffer(1), lSize)
sTemp = StrConv(MidB$(bytBuffer, LenB(uIPI) + 1), vbUnicode)
lPos = InStr(1, sTemp, Chr$(0))
sProxy = Left$(sTemp, lPos - 1)
sProxyBypass = Mid$(sTemp, lPos + 1, Len(sTemp) - lPos - 1)
Debug.Print "Temp:"; sTemp
Debug.Print "Proxy:"; sProxy
Debug.Print "ProxyBypass:"; sProxyBypass
End Sub
>WinInet is causing me no end of troubles so I'd appreciate any advice.
>
It's seems that you are in the exact same stage as I were a few months ago
:-) ... frustrated and TOTALLY ready to take WinInet out to the parking lot
and burn it (if it only was something you can touch).
Well, let's see if I can help you. I'm working for a company X, that has
activities all around the world. My task was to create an ActiveX control
that you pass information to, and then it would do it's magic
(upload/download files from our web server to/from the client's hard
drive).
The good thing is that we are working inside the company Intranet all the
time. The download procedure was quite easy to code (I never had any
problems with proxy). The problems actually began when I started to code
the upload procedure. The upload from the client to the web server was
working just fine, when I was uploading files within my computer and a web
server that was located in the same room. The problems occured when I
started to do upload to a web server that was located in our Intranet but
in another town. At this stage I started to get error messages, the answer
actually located in here:
http://support.microsoft.com/support/kb/articles/Q249/5/94.ASP
But that wasn't the end of it. The case was, that it had to work exactly
like it would from the IE, which basically means that you can't show the
user any Proxy Authentication Dialogs. I mean you can get pass the Proxy by
using the code example mentioned above, but it didn't help in my case. I
also tried almost every possible option when creating the connection to the
server but none of the options that have something to do with the Proxy
didn't help me.. it always gave me the Dialog window :(
At this stage I saw someone mentioning that you can get pass these error
messages (120030, 120031 etc.) if you just resend the file. So what I did
was, that I removed the InternetErrorDlg from the example (of course at
this stage the MS example was quite heavily modified) and did a Goto and
resend the file.... SUCCESS! It always passes the Proxy on the second or
the third try. The problem with this is that you spend a lot of extra time
sending unnecessary data to "cheat" the proxy to allow it to pass your
file. The answer to this was, that I always "open" the proxy be sending
empty data to it. When I get an success from the
HttpEndRequest/HttpQueryInfo, I'll send the real data. This seems to be
working like I clock, at least in my environment.
I hope this gives you some advices...
What error do you get the second time thru?
--
Michael Shutt
Please respond to newsgroup as I will not return direct emails.
Hi Michael,
My LastDllError is 12029 which appears to be: ERROR_INTERNET_CANNOT_CONNECT
#define INTERNET_ERROR_BASE 12000
#define ERROR_INTERNET_CANNOT_CONNECT (INTERNET_ERROR_BASE + 29)
I'll explain what happens...attempting to access an external site... I open all
the internet handles I need (access is INTERNET_OPEN_TYPE_PRECONFIG) and attempt a
connection outside our firewall. On doing a HttpSendRequest and a HttpQueryInfo I
get a proxy authentication error as expected and I pop-up the appropriate dialog.
If I type the wrong username/password I do a loop and do a resend with
HttpSendRequest and another HttpQueryInfo. This bit works and will keep going till
I either cancel or enter the correct details. The routine exits by closing all the
open handles.
Now, assuming I didn't enter the proxy username/password, when I run the routine a
second time this is when HttpSendRequest will hang for about 30s and fail (it is
effectively trying INTERNET_OPEN_TYPE_DIRECT access) and then when I check
LastDllError it is 12029. To get the routine working again so it gives me a proxy
authenication error when using INTERNET_OPEN_TYPE_PRECONFIG I have to restart
Excel/VBA. If I were to switch to INTERNET_OPEN_TYPE_PROXY I don't have to restart
but I have my local access problem (see below).
When I use INTERNET_OPEN_TYPE_PROXY with OpenInternet I can run the routine over
and over using the same test case and it doesn't ever hang. The problem here is
that when I try to get OpenInternet to use a bypass list it ignores the directive
'<local>' that should enable it to access the intranet without the proxy and I get
a proxy authenication error - the user will not expect to enter their
username/password for an internal intranet site (like IE).
When I use INTERNET_OPEN_TYPE_DIRECT with OpenInternet it hangs for about 30s and
fails as I'd expect because I am using a proxy and trying to get outside! However,
if I change the access type to INTERNET_OPEN_TYPE_PROXY and re-run the routine
then I get the authentication error that I can deal with.
So in summary, INTERNET_OPEN_TYPE_PRECONFIG works first time I run my procedure
and gives me an appropriate proxy authentication error - it will do this again and
again until I either enter the correct username/password or cancel. I then exit
the procedure and close all open handles. 2nd time around InternetOpen seems to be
using INTERNET_OPEN_TYPE_DIRECT instead of INTERNET_OPEN_TYPE_PROXY and so hangs
and fails without a proxy authenication error. I have to exit Excel/VBA to get
InternetOpen/INTERNET_OPEN_TYPE_PRECONFIG to use INTERNET_OPEN_TYPE_PROXY again.
Thanks for any light you can shed on this. I have included my routine below.
Jonathan.
____________________________________________________________________________
Public Sub InternetTest()
Dim hOpenHandle As Long
Dim hConnectHandle As Long
Dim hResourceHandle As Long
Dim dwError As Long
Dim dwErrorCode As Long
Dim lSize as Long
hOpenHandle = InternetOpen("Example", INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
hConnectHandle = InternetConnect(hOpenHandle, "mirror.aarnet.edu.au", _
INTERNET_INVALID_PORT_NUMBER, vbNullString, _
vbNullString, INTERNET_SERVICE_HTTP, 0, 0)
hResourceHandle = HttpOpenRequest(hConnectHandle, "GET",
"/pub/microsoft/fixes/nt/utilities/Sysdiff-fix/Q154745.TXT", _
vbNullString, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or
INTERNET_FLAG_DONT_CACHE Or INTERNET_FLAG_KEEP_CONNECTION, 0)
resend:
Debug.Print "HttpSendRequest:"; HttpSendRequest(hResourceHandle, vbNullString,
0, vbNullString, 0)
lSize = LenB(dwErrorCode)
Debug.Print "HttpQueryInfo:" & HttpQueryInfo(hResourceHandle,
HTTP_QUERY_STATUS_CODE + HTTP_QUERY_FLAG_NUMBER, dwErrorCode, lSize, ByVal 0&)
dwError = InternetErrorDlg(ByVal GetDesktopWindow(), hResourceHandle,
dwErrorCode, _
FLAGS_ERROR_UI_FILTER_FOR_ERRORS Or _
FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS Or _
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA, _
ByVal 0&)
If (dwError = ERROR_INTERNET_FORCE_RETRY) Then GoTo resend
'Code to download to go here
If hResourceHandle Then InternetCloseHandle hResourceHandle
If hConnectHandle Then InternetCloseHandle hConnectHandle
If hOpenHandle Then InternetCloseHandle hOpenHandle
End Sub
Couldn't agree more but I'd like to shoot it!
Thanks for your advice Skaba but I think my problem is slightly different as I get
an error 12029 (ERROR_INTERNET_CANNOT_CONNECT) and am using HttpSendRequest (not
HttpSendRequestEx). If you're still interested have a look at my explanation in
reply to Michael Stutt.
Cheers,
Jonathan.
tia,
joachim kraeuter
Skaba <eek...@hotmail.com> wrote in message
news:C3OM6.108$Vg5....@read2.inet.fi...
Alternatively, I would compare the headers being sent by the first call to
HttpSendRequest to the headers being sent the second time (although you
don't seem to be supplying any, WinInet is adding some). I have found that
sometimes WinInet gets them wrong the second time thru and you have to
manually correct them by using InternetSetOption.
--
Michael Shutt
Please respond to newsgroup as I will not return direct emails.
<snip>