Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find auto-config proxy for http AND ftp protocol with WPAD

130 views
Skip to first unread message

Torbjörn Håkansson

unread,
Aug 1, 2003, 8:58:08 AM8/1/03
to
Hi
 
I wonder if somebody have some experience with how to get proxy-servers auto-configurable addresses.
 
I and our company develop a software which depends on http and ftp i VB6. Some of our customers use automatic detect proxy servers in IE6. I need to develop the same functions for our software ( our components from IP-works needs this settings to work). I have tested different server software to learn how this WPAD magic works. At this moment my test-server is a win2000 server with a DNS and a DHCP server configured to answer for incoming request, and I use MS Proxy 2 as proxy server.  My wpad.dat file is like this:
 
function FindProxyForURL(url, host)
{
 if (url.substring(0, 5) == "http:")
 {
  return "PROXY 192.168.1.1:80";
 }
 else if (url.substring(0, 4) == "ftp:")
 {
  //If I use SOCKS server for FTP like UNIX do   
  //return "SOCKS 192.168.1.1:1080";
 
  // If I use MS Proxy2 server and use the client use winsock - go directly
  return "DIRECT";
 }
 else
 {
  // Some other protocol - for test only
  return "PROXY 192.168.1.2:80";
  //return "DIRECT";
 }
}     
 

This wpad.dat file works perfectly in IE6, do I use ftp://some-server  in the adressbar  it connects perfectly.
 

Now to the problem, I have tried to get this info for some time now ( some weeks ) , I have used wininet.h functions to find out this.  The function DetectAutoProxyUrl perfect finds the address for my WPAD file , but the pfnInternetGetProxyInfo in the jsproxy.dll can't resolve the correct answer:
 
the code snippet:
 
 if( !pInternetGetProxyInfo(  (LPSTR)url ,  sizeof( url ),
         (LPSTR) host, sizeof( host ),
         &proxy, &dwProxyHostNameLength ) )
 {
  reportFuncErr( "InternetGetProxyInfo", myError );
  *bstrFTPProxy =A2BSTR(myError);
  *lResult = -1;
  return S_OK;
 }
 else
 {
  ATLTRACE( "\n  Proxy is: %s\n", proxy );
  *bstrHttpProxy = A2BSTR(proxy);
 }
 
If I use http or ftp for my url it always report back PROXY 192.168.1.2:80 which is a wrong answer, IE6 solves this, why not this function?
 

The second solution is to use the new function WinHttpGetProxyForUrl in winhttp.dll 5.1 , this function seems to resolve the correct server-address for http addresses. But if I use some url for ftp like ftp://some-server  it answer 12006 - ERROR_WINHTTP_UNRECOGNIZED_SCHEME. If I understands correctly winhttp don't support ftp ?
 

Some info, All our code is in VB6 but this I have made in ATL/VC++ as a object.
 
Is there somebody who can solve my problem. The best solution would be to use the old functions in wininet.h mostly for our customers use win98 , NT4 and you have to use win2k sp3 or winxp sp1 to use winhttp.dll 5.1.
 
In worst case I have to interp the info in the WPAD file myself.
 

Regards
 
Torbjörn Håkansson
Developer
Introibis
http://introibis.com
Sweden
 
 
 
 
 
 
 

 
 
 

Stephen Sulzer

unread,
Aug 2, 2003, 6:54:49 AM8/2/03
to
Hello.
 
The fact that InternetGetProxyInfo is returning "192.168.1.2:80" suggests that, at least, the WPAD script code is being loaded into JSPROXY successfully and executing. So I would be suspicious of the value of the url string parameter being passed to FindProxyForUrl.
 
 
When you integrated this sample code into your component, did you change the types of the url (and/or host) string variables (that are passed to the pInternetGetProxyInfo function)?
 
The WinInet sample code assumes the types of these variables are character arrays, and uses the sizeof compile-time function to determine their string lengths. But if you changed the types of these variables to character pointers (char *), then you must use the strlen function instead to compute the string lengths. Using sizeof on a char* type of course returns the size of a pointer (e.g., 4 bytes) and not the length of the string the pointer points to.  So I would change the sizeof(url) and sizeof(host) to strlen(url) and strlen(host) in your code. That is the only thing I can think of that would explain the problem.
 
Regarding WinHttpGetProxyForUrl, it is true that it accepts only http: and https: URLs. Which likely means you will still need to use WinInet/JSPROXY autoproxy functions (at least for ftp: URLs) on all platforms.
 
 
Hope that helps.
 
 
    Stephen
 
 
"Torbjörn Håkansson" <torb...@introibis.com> wrote in message news:eOGKQyC...@tk2msftngp13.phx.gbl...

Torbjörn Håkansson

unread,
Aug 4, 2003, 3:45:23 AM8/4/03
to
 
Thanks Steven for your reply
 
Yes , I saw my mistake a hour later , when I debugged my VB test client program. The conversion from BSTR to LPSTR was incorrect. Only the first character was sent to JSPROXY, if I test http://something I sent only "h". So the JSPROXY interped the url correct.
 
My problem was that MS sample didn't work also, from MS sample
char url[1025] = "<http://www.microsoft.com/windows/default.mspx>";
 
I don't no why MS use "<" ">" , this extra char did that my wpad.dat file don't work, and I could not see why.
 

But now all works
 
 
Torbjörn
 
 
0 new messages