Discussion:
PAC auto detection FAILED....
(too old to reply)
selva
2006-11-08 06:19:17 UTC
Permalink
i use the following code in c# for detecting the PAC file
Automatically....
if i give the url of the PAC file explicitly then it returning me the
appropriate proxy....
if i use WINHTTP_AUTOPROXY_AUTO_DETECT flag set it's returning me the
error 12180...
please help me regarding this issue....

Class Proxytest.cs

using System;
using System.Net;
using System.IO;
using WinHttp;
namespace PacProxyUsage
{
/// <summary>
/// Summary description for ProxyTest.
/// </summary>
class ProxyTest
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Stream RequestStream = null;
string DestinationUrl = "http://www.google.co.in";
string PacUri = "http://wpad/wpad.dat";

// Create test request
WebRequest TestRequest = WebRequest.Create ( DestinationUrl );
WinHttpRequest req=new WinHttpRequest();
// Optain Proxy address for the URL
string ProxyAddresForUrl = Proxy.GetProxyForUrlUsingPac (
DestinationUrl, PacUri );
if ( ProxyAddresForUrl != null ){
Console.WriteLine ("Found Proxy: {0}",
ProxyAddresForUrl );
TestRequest.Proxy = new WebProxy ( ProxyAddresForUrl )
;
}else{
Console.WriteLine ( "Proxy Not Found. Send request
directly." );
}

try {
//req.Open("POST","http://www.google.com",false);
//req.SetCredentials( "e363757" ,"Gocomegocome1983" , 1 );
WebResponse TestResponse = TestRequest.GetResponse();
//req.Send(0);
//Console.WriteLine(req.Status);

Console.WriteLine ( "Request was successful" );
}catch ( Exception ex ){
Console.WriteLine ( "Error: {0}", ex.Message );
}finally{
if ( RequestStream != null ){
RequestStream.Close();
}
}
Console.ReadLine();
}
}
}


Class Proxy.cs

using System;
using WinHttp;


namespace PacProxyUsage
{
/// <summary>
/// Summary description for Proxy.
/// </summary>
public class Proxy
{
public Proxy()
{
}

/// <summary>
/// Return proxy for requested Url
/// </summary>
/// <param name="sUrl">url</param>
/// <param name="sPacUri">Uri to PAC file</param>
/// <returns>proxy info</returns>
public static string GetProxyForUrlUsingPac ( string
DestinationUrl,String PacUri ){



IntPtr WinHttpSession = Win32Api.WinHttpOpen("User",
Win32Api.WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,

IntPtr.Zero, IntPtr.Zero, 0);
Win32Api.WINHTTP_AUTOPROXY_OPTIONS ProxyOptions = new
Win32Api.WINHTTP_AUTOPROXY_OPTIONS();
Win32Api.WINHTTP_PROXY_INFO ProxyInfo = new
Win32Api.WINHTTP_PROXY_INFO();
ProxyOptions.dwFlags =
Win32Api.WINHTTP_AUTOPROXY_CONFIG_URL;
//ProxyOptions.dwFlags =
Win32Api.WINHTTP_AUTOPROXY_AUTO_DETECT ;
//ProxyOptions.dwAutoDetectFlags =
(Win32Api.WINHTTP_AUTO_DETECT_TYPE_DHCP |

Win32Api.WINHTTP_AUTO_DETECT_TYPE_DNS_A);
ProxyOptions.lpszAutoConfigUrl = PacUri;
// string result;
// Get Proxy
bool IsSuccess = Win32Api.WinHttpGetProxyForUrl(
WinHttpSession, DestinationUrl, ref ProxyOptions, ref

ProxyInfo );



Console.WriteLine("Error: {0}", Win32Api.GetLastError() );

Win32Api.WinHttpCloseHandle(WinHttpSession);

if ( IsSuccess ){
return ProxyInfo.lpszProxy;
}else {
Console.WriteLine("Error: {0}", Win32Api.GetLastError()
);
return null;
}
}

}
}

Regards
BHARATHI
Stephen Sulzer
2006-11-08 09:28:55 UTC
Permalink
How does the fully-qualified domain name (FQDN) of your wpad server compare
with the FQDN of the computer that is running your ProxyTest code? Run
"ipconfig /all" from a command prompt on the ProxyTest computer and look at
the Primary Dns Suffix value. Is the wpad server located within the same
domain?

That is, suppose the Primary Dns suffix of your ProxyTest computer is
"aaa.yahoo.co.in". Then the FQDN of the wpad server must be either
"wpad.aaa.yahoo.co.in" or "wpad.yahoo.co.in". If neither of those FQDN is
resolvable, then WinHttp's proxy discovery logic will fail.

- Stephen
selva
2006-11-08 10:31:31 UTC
Permalink
thanks stephen
my WPAD SERVER is not located with in the primary DNS
Suffix.
if i type http:\\wpad\wpad.dat in the IE it's displaying
the PAC file.
then is there any other remedy for this issue ........what
i have to do now?
please help me to solve this issue

regards
bharathi
Post by Stephen Sulzer
How does the fully-qualified domain name (FQDN) of your wpad server compare
with the FQDN of the computer that is running your ProxyTest code? Run
"ipconfig /all" from a command prompt on the ProxyTest computer and look at
the Primary Dns Suffix value. Is the wpad server located within the same
domain?
That is, suppose the Primary Dns suffix of your ProxyTest computer is
"aaa.yahoo.co.in". Then the FQDN of the wpad server must be either
"wpad.aaa.yahoo.co.in" or "wpad.yahoo.co.in". If neither of those FQDN is
resolvable, then WinHttp's proxy discovery logic will fail.
- Stephen
Stephen Sulzer
2006-11-09 08:40:06 UTC
Permalink
bharathi,

My recommendation is to call WinHttpGetProxyForUrl specifying both the
AUTO_DETECT and CONFIG_URL options. For the AutoConfigUrl, specify
"http://wpad/wpad.dat".


Win32Api.WINHTTP_AUTOPROXY_OPTIONS ProxyOptions = new
Win32Api.WINHTTP_AUTOPROXY_OPTIONS();

Win32Api.WINHTTP_PROXY_INFO ProxyInfo = new Win32Api.WINHTTP_PROXY_INFO();

ProxyOptions.dwFlags = (Win32Api.WINHTTP_AUTOPROXY_AUTO_DETECT |
Win32Api.WINHTTP_AUTOPROXY_CONFIG_URL);

ProxyOptions.dwAutoDetectFlags = (Win32Api.WINHTTP_AUTO_DETECT_TYPE_DHCP |
Win32Api.WINHTTP_AUTO_DETECT_TYPE_DNS_A);

ProxyOptions.lpszAutoConfigUrl = "http://wpad/wpad.dat"; // or
AutoConfigUrl found by WinHttpGetIEProxyConfigForCurrentUser

bool IsSuccess = Win32Api.WinHttpGetProxyForUrl(WinHttpSession,
DestinationUrl, ref ProxyOptions, ref ProxyInfo);


With this configuration, WinHttpGetProxyForUrl will first try to discover
the PAC URL using DHCP and DNS queries as per the WPAD algorithm. (The DNS
queries will look for the wpad server using the Primary Dns suffix of the
host computer.) If auto-detection fails, then WinHttp will try the
"http://wpad/wpad.dat" AutoConfigUrl. If the "wpad" DNS name is resolveable
but is not in the same domain as the host computer (as it is in your
situation) then this fallback should work. "wpad" is a well-known server
name used in deploying the PAC file, so this approach should work in a lot
of (corporate) network environments.

Of course, also use the WinHttpGetIEProxyConfigForCurrentUser API which will
tell you how IE is configured (and may give you a workable AutoConfigUrl).

Hope that helps.

Regards,
- Stephen
selva
2006-11-09 08:59:17 UTC
Permalink
thanks stephen
i hope it will help me lot
regards
bharathi
Post by Stephen Sulzer
bharathi,
My recommendation is to call WinHttpGetProxyForUrl specifying both the
AUTO_DETECT and CONFIG_URL options. For the AutoConfigUrl, specify
"http://wpad/wpad.dat".
Win32Api.WINHTTP_AUTOPROXY_OPTIONS ProxyOptions = new
Win32Api.WINHTTP_AUTOPROXY_OPTIONS();
Win32Api.WINHTTP_PROXY_INFO ProxyInfo = new Win32Api.WINHTTP_PROXY_INFO();
ProxyOptions.dwFlags = (Win32Api.WINHTTP_AUTOPROXY_AUTO_DETECT |
Win32Api.WINHTTP_AUTOPROXY_CONFIG_URL);
ProxyOptions.dwAutoDetectFlags = (Win32Api.WINHTTP_AUTO_DETECT_TYPE_DHCP |
Win32Api.WINHTTP_AUTO_DETECT_TYPE_DNS_A);
ProxyOptions.lpszAutoConfigUrl = "http://wpad/wpad.dat"; // or
AutoConfigUrl found by WinHttpGetIEProxyConfigForCurrentUser
bool IsSuccess = Win32Api.WinHttpGetProxyForUrl(WinHttpSession,
DestinationUrl, ref ProxyOptions, ref ProxyInfo);
With this configuration, WinHttpGetProxyForUrl will first try to discover
the PAC URL using DHCP and DNS queries as per the WPAD algorithm. (The DNS
queries will look for the wpad server using the Primary Dns suffix of the
host computer.) If auto-detection fails, then WinHttp will try the
"http://wpad/wpad.dat" AutoConfigUrl. If the "wpad" DNS name is resolveable
but is not in the same domain as the host computer (as it is in your
situation) then this fallback should work. "wpad" is a well-known server
name used in deploying the PAC file, so this approach should work in a lot
of (corporate) network environments.
Of course, also use the WinHttpGetIEProxyConfigForCurrentUser API which will
tell you how IE is configured (and may give you a workable AutoConfigUrl).
Hope that helps.
Regards,
- Stephen
selva
2006-11-10 05:03:48 UTC
Permalink
hi stephen
i found that my IE is working fine
when i enables the auto detection mode how come it's possible
for my IE to detect my PAC, if it is not in the primary DNS suffix of
my system actually my PAC file is in http://wpad/wpad.dat

regards
bharathi
Post by Stephen Sulzer
bharathi,
My recommendation is to call WinHttpGetProxyForUrl specifying both the
AUTO_DETECT and CONFIG_URL options. For the AutoConfigUrl, specify
"http://wpad/wpad.dat".
Win32Api.WINHTTP_AUTOPROXY_OPTIONS ProxyOptions = new
Win32Api.WINHTTP_AUTOPROXY_OPTIONS();
Win32Api.WINHTTP_PROXY_INFO ProxyInfo = new Win32Api.WINHTTP_PROXY_INFO();
ProxyOptions.dwFlags = (Win32Api.WINHTTP_AUTOPROXY_AUTO_DETECT |
Win32Api.WINHTTP_AUTOPROXY_CONFIG_URL);
ProxyOptions.dwAutoDetectFlags = (Win32Api.WINHTTP_AUTO_DETECT_TYPE_DHCP |
Win32Api.WINHTTP_AUTO_DETECT_TYPE_DNS_A);
ProxyOptions.lpszAutoConfigUrl = "http://wpad/wpad.dat"; // or
AutoConfigUrl found by WinHttpGetIEProxyConfigForCurrentUser
bool IsSuccess = Win32Api.WinHttpGetProxyForUrl(WinHttpSession,
DestinationUrl, ref ProxyOptions, ref ProxyInfo);
With this configuration, WinHttpGetProxyForUrl will first try to discover
the PAC URL using DHCP and DNS queries as per the WPAD algorithm. (The DNS
queries will look for the wpad server using the Primary Dns suffix of the
host computer.) If auto-detection fails, then WinHttp will try the
"http://wpad/wpad.dat" AutoConfigUrl. If the "wpad" DNS name is resolveable
but is not in the same domain as the host computer (as it is in your
situation) then this fallback should work. "wpad" is a well-known server
name used in deploying the PAC file, so this approach should work in a lot
of (corporate) network environments.
Of course, also use the WinHttpGetIEProxyConfigForCurrentUser API which will
tell you how IE is configured (and may give you a workable AutoConfigUrl).
Hope that helps.
Regards,
- Stephen
Continue reading on narkive:
Loading...