473,378 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

using proxy auto config (.PAC) script for web request


I am having trouble accessing a web page programmatically from .NET. Our
proxy server is determined by a PAC script and all the standard .NET (and
WinHttp) proxy techniques don't work for scripts.

My current state is that I use the WinInet function
'InternetQueryOptionList' to get the proxy settings. This is working fine, I
am able to detect that my IE settings use a PAC script.

Next, I try using the WinHttp function 'WinHttpDetectAutoProxyConfigUrl' to
get the proxy address. This always fails. If I pass 0 for the handle, it
returns error 6 (invalid handle). If I use WinHttpOpen to get a handle and
pass that into the function, it returns error 87 (invalid parms).

I'm guessing that my marshalling is incorrect, so I include the code below.
Any help is appreciated.

Thanks, Richard

public class WinHttpWrapper
{
[System.Runtime.InteropServices.DllImport("winhttp. dll", EntryPoint =
"WinHttpGetProxyForUrl")]
public extern static bool WinHttpGetProxyForUrl(IntPtr handle, string url,
ref WINHTTP_AUTOPROXY_OPTIONS proxyOptions, out WINHTTP_PROXY_INFO proxyInfo);

[System.Runtime.InteropServices.DllImport("winhttp. dll", EntryPoint =
"WinHttpDetectAutoProxyConfigUrl")]
public extern static bool WinHttpDetectAutoProxyConfigUrl(uint
autoDetectFlags, out string url);

[System.Runtime.InteropServices.DllImport("winhttp. dll", EntryPoint =
"WinHttpOpen")]
public extern static IntPtr WinHttpOpen(string userAgent, uint accessType,
string proxyName, string bypassName, uint flags);

[System.Runtime.InteropServices.DllImport("winhttp. dll", EntryPoint =
"WinHttpCloseHandle")]
public extern static bool WinHttpCloseHandle(IntPtr handle);
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct WINHTTP_AUTOPROXY_OPTIONS
{
public uint dwFlags;
public uint dwAutoDetectFlags;
public string lpszAutoConfigUrl;
public IntPtr lpvReserved;
public uint dwReserved;
public bool fAutoLoginIfChallenged;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct WINHTTP_PROXY_INFO
{
public uint dwAccessType;
public string lpszProxy;
public string lpszProxyBypass;
}
Jul 21 '05 #1
0 5002

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: RandRace | last post by:
what is the correct way to use a proxy server? i've set up a user agent named $browser and assigned it $browser->agent('Mozilla/4.0(compatible;MSIE 6.0;Windows NT 5.0)' ); print $browser->agent;...
1
by: solex | last post by:
If you have, can you please point me in the right direction as to how to get this to work. TIA, Dan
0
by: Richard | last post by:
I am having trouble accessing a web page programmatically from .NET. Our proxy server is determined by a PAC script and all the standard .NET (and WinHttp) proxy techniques don't work for scripts....
1
by: jonathan Cook | last post by:
I have written a .NET client which calls a webservice. I've added functionality in which allows authentication through a proxy. When sending a GET request this works but when I do a POST I get a...
6
by: Joel H | last post by:
We have several settings in web.config that are different on the developer side than the production side. Our website sourcecode is under sourcesafe control, so before we code, we check out the...
3
by: Nathan | last post by:
Have a strange problem. Creating a windows service running under the Local Sytem account. I have a Webclient that downloads a file from the internet. The code works fine if executed from a windows...
2
by: Adam | last post by:
Hi, everyone, I am using /usr/share/system-config-language/ language_gui.py in Python. For some reason I have to bypass the firewall using a proxy. I read the urllib reference and set...
1
by: richard | last post by:
We have developed a website using ajax toolkit in asp.net 2.0 During web development everything work fine. When we deploy at live environment, the client is using proxy server. We found out the...
3
by: Robin9876 | last post by:
In IIS 7 I have created a web site which is located at C:\MyWebSite and in IIS Manager created a virtual folder which points to C: \MyVirtualFolder. The virtual folder was then converted to an...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.