Federico Sasso
2004-08-13 07:30:30 UTC
Hi all
Thist of all, sorry for X-posting, but the question involves both wininet
and C# interop ;-)
I wrote a simple FTP client in C# using p/Invoke over Wininet.dll API
functions. It works fine, as it transparently passes ISA proxy/firewall when
this doesn't require authentication.
Now I want to modify it to handle proxy authentication.
I read on msdn
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/setting_and_retrieving_internet_options.asp
("Setting individual options" section) a little snippet inviting to set the
proxy user and password with InternetSetOption() using values for
INTERNET_OPTION_PROXY_USERNAME and INTERNET_OPTION_PROXY_ PASSWORD
I tried accomplishing this with:
if (!InternetSetOption(
hInternet,
INTERNET_OPTION_PROXY_USERNAME,
Marshal.StringToHGlobalAuto(proxyUser),
proxyUser.Length))
throw new Win32Exception(Marshal.GetLastWin32Error());
where hInternet is the handle returned by InternetOpen(), and
InternetSetOption() is defined as:
[DllImport("wininet.dll", SetLastError = true)]
public static extern bool InternetSetOption
(
IntPtr hInternet,
int dwOption,
IntPtr lpBuffer,
int lpdwBufferLength
);
Unfortunately I always obtain the Win32Exception (Unknown error (0x2ef2),
which doesn't help a lot).
I got several doubts:
1) is the call Marshal.StringToHGlobalAuto(proxyUser) correct?
2) is using proxyUser.Length correct? or should I add a *2 factor to comply
with Unicode char size?
3) how can I specify a domain other than user and password?
4) in InternetOpen() I tried both INTERNET_OPEN_TYPE_DIRECT (which I used
previously) to INTERNET_OPEN_TYPE_PROXY, and specify a proxy name, but the
behavior didn't change. Which is right?
5) I tried writing the proxy name in several ways: "srv-isa:8080",
"http://srv-isa:8080", "ftp://srv-isa:8080", which is the right one?
Please enlighten me.
Fred
-
Federico Sasso &8v>
http://www.crt.unige.it/jsSQL
The jsSQL Project - JavaScript Database and SQL Engine
Thist of all, sorry for X-posting, but the question involves both wininet
and C# interop ;-)
I wrote a simple FTP client in C# using p/Invoke over Wininet.dll API
functions. It works fine, as it transparently passes ISA proxy/firewall when
this doesn't require authentication.
Now I want to modify it to handle proxy authentication.
I read on msdn
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/setting_and_retrieving_internet_options.asp
("Setting individual options" section) a little snippet inviting to set the
proxy user and password with InternetSetOption() using values for
INTERNET_OPTION_PROXY_USERNAME and INTERNET_OPTION_PROXY_ PASSWORD
I tried accomplishing this with:
if (!InternetSetOption(
hInternet,
INTERNET_OPTION_PROXY_USERNAME,
Marshal.StringToHGlobalAuto(proxyUser),
proxyUser.Length))
throw new Win32Exception(Marshal.GetLastWin32Error());
where hInternet is the handle returned by InternetOpen(), and
InternetSetOption() is defined as:
[DllImport("wininet.dll", SetLastError = true)]
public static extern bool InternetSetOption
(
IntPtr hInternet,
int dwOption,
IntPtr lpBuffer,
int lpdwBufferLength
);
Unfortunately I always obtain the Win32Exception (Unknown error (0x2ef2),
which doesn't help a lot).
I got several doubts:
1) is the call Marshal.StringToHGlobalAuto(proxyUser) correct?
2) is using proxyUser.Length correct? or should I add a *2 factor to comply
with Unicode char size?
3) how can I specify a domain other than user and password?
4) in InternetOpen() I tried both INTERNET_OPEN_TYPE_DIRECT (which I used
previously) to INTERNET_OPEN_TYPE_PROXY, and specify a proxy name, but the
behavior didn't change. Which is right?
5) I tried writing the proxy name in several ways: "srv-isa:8080",
"http://srv-isa:8080", "ftp://srv-isa:8080", which is the right one?
Please enlighten me.
Fred
-
Federico Sasso &8v>
http://www.crt.unige.it/jsSQL
The jsSQL Project - JavaScript Database and SQL Engine