Здравствуйте, Passerby, Вы писали:
P>У меня не веб-сайт, а обычный домашний ПК. Итак, создаю новый проект, пишу HttpClient client=new(); Какой код дальше и куда помещать pac?
Туда, куда вы сможете построить URL.
Например, можете брать прямо с
https://antizapret.prostovpn.org:8443/proxy.pac
P>У меня NET 8.
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.com";
string PacUri = "http://127.0.0.1/proxy.pac1"; // вот здесь указываете URL к вашему PAC-файлу
// Create test request
WebRequest TestRequest = WebRequest.Create ( DestinationUrl );
// 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 {
WebResponse TestResponse = TestRequest.GetResponse();
Console.WriteLine ( "Request was successful" );
}catch ( Exception ex ){
Console.WriteLine ( "Error: {0}", ex.Message );
}finally{
if ( RequestStream != null ){
RequestStream.Close();
}
}
Console.ReadLine();
}
}