无法使用代理下载URL [英] Unable to download a URL using proxy
问题描述
我正在尝试下载belo网址
[ ^ ]
[ ^ ]
我可以在不提及代理的情况下下载上述URL。
如果我设置代理我收到错误消息错误尝试自动重定向太多。
如果您需要更多信息,请告诉我。
谢谢,
Siddi。
我尝试了什么:
以下是我尝试过的不同选项:
使用System;
使用System.Coll ections.Generic;
使用System.Linq;
使用System.Net;
使用System.Text;
使用System.Threading.Tasks;
使用System.Diagnostics;
使用System.IO;
命名空间AutoRedirect
{
class program
{
static string pilotSecuritiesFilePath = @C:\ FINRA \\ \\pilotSecuritiesProxy.txt; // GetPilotSecuritiesFilePath();
静态字符串pilotChangesFilePath = @C:\ FININRA \pilotChangesProxy.txt; // GetPilotChangesFilePath();
static string masterURL =http://tsp.finra.org/finra_org/ticksizepilot/TSPrePilotSecurities.txt;
static string changeURL =http://tsp.finra.org/finra_org /ticksizepilot/TSPrePilotChanges.txt;
静态字符串sSource;
静态字符串sLog;
静态字符串sEvent;
static string filePath = @C:\ FININ \\ LOG.txt;
static void Main(string [] args)
{
sSource = AutoRedirectApp;
sLog =申请;
sEvent =AutoRedirect;
if( File.Exists(filePath))
{
File.Delete(filePath);
}
// if(!EventLog.SourceExists(sSource))
// EventLog.CreateEventSource(sSource,sLog);
DownloadPilotSecuritiesWithoutProxy();
DownloadPilotSecurities();
DownloadUsingWebRequestWithoutProxy();
DownloadUsingWebRequestWithProxy();
DownloadUsingWebRequestWithProxyMaxRedirections();
DownloadUsingWebRequestWithProxyWithBaseURL();
}
private static void DownloadPilotSecuritiesWithoutProxy()
{
// LogMessage(使用没有代理的WebClient下载:开始);
尝试使用(WebClient webClient = new WebClient())
$
b $ b //webClient.BaseAddress =http://www.finra.org/;
webClient.DownloadFile(masterURL,pilotSecuritiesFilePath);
webClient.DownloadFile (changeURL,pilotChangesFilePath);
}
}
catch(例外情况)
{
EventLog.WriteEntry(sSource,ex.Message);
//LogMessage(ex.Message);
LogMessage(使用没有代理的WebClient下载:错误+ ex.Message);
}
LogMessage(使用没有代理的WebClient下载:已完成);
}
private static void DownloadPilotSecurities()
{
// LogMessage(使用带代理的WebClient下载:已启动);
尝试使用(WebClient webClient = new WebClient())
$
b $ b WebProxy wp = new WebProxy(http://SomeProxy.pac);
webClient.Proxy = wp;
//webClient.BaseAddress =http ://www.finra.org/;
webClient.DownloadFile(masterURL,pilotSecuritiesFilePath);
webClient.DownloadFile(changeURL,pilotChangesFilePath);
}
LogMessage(使用带代理的WebClient下载:已完成);
}
catch(Exception ex)
{
//EventLog.WriteEntry(sSource,ex.Message);
Console.WriteLine(ex.Message);
//LogMessage(ex.Message);
LogMessage(使用下载带代理的WebClient:错误+ ex.Message);
}
}
private static void DownloadUsingWebRequestWithoutProxy()
{
// LogMessage(使用没有代理的WebRequest下载:已启动);
HttpWebRequest webReq =(HttpWebRequest)WebRequest.Create(masterURL) ;
字符串res;
尝试
{
webReq.Method =GET;
使用(WebResponse response = webReq.GetResponse())
{
using(Stream stream = response .GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd();
}
}
File.AppendAllText(pilotSecuritiesFilePath,res);
LogMessage( 使用没有代理的WebRequest下载:已完成);
}
catch(例外情况)
{
LogMessage(使用没有代理的WebRequest下载:错误+ ex.Message);
}
}
private static void DownloadUsingWebRequestWithProxy()
{
// LogMessage(使用没有代理的WebRequest下载:已启动);
HttpWebRequest webReq =(HttpWebRequest)WebRequest.Create(masterURL);
CookieContainer cookieContainer = new CookieContainer();
string res;
try
{
webReq。 Method =GET;
WebProxy wp = new WebProxy(http://SomeProxy.pac);
webReq.Proxy = wp;
webReq.CookieContainer = cookieContainer;
使用(WebResponse response = webReq.GetResponse())
{
using(Stream stream = response .GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd();
}
}
File.AppendAllText(pilotSecuritiesFilePath,res);
LogMessage( 通过代理下载使用WebRequest:已完成);
}
catch(例外情况)
{
LogMessage(使用带代理的WebRequest下载:错误+ ex.Message);
}
}
private static void DownloadUsingWebRequestWithProxyMaxRedirections()
{
// LogMessage(使用没有代理的WebRequest下载:已启动);
HttpWebRequest webReq =(HttpWebRequest)WebRequest.Create(masterURL);
CookieContainer cookieContainer = new CookieContainer( );
string res;
try
{
webReq.Method =GET;
WebProxy wp = new WebProxy(http://SomeProxy.pac);
webReq.Proxy = wp;
webReq.CookieContainer = cookieContainer;
webReq.MaximumAutomaticRedirections = 10000;
使用(WebResponse response = webReq.GetResponse())
{
使用(Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd();
}
}
File.AppendAllText(pilotSecuritiesFilePath,res) ;
LogMessage(使用带有最大重定向的代理的WebRequest下载:已完成);
}
catch(Exception ex)
{
LogMessage(使用带有Max重定向的代理的WebRequest下载:错误+ ex.Message);
}
}
private static void LogMessage(string message)
{
File.AppendAllText(filePath,Environment.NewLine + message);
}
private static void DownloadUsingWebRequestWithProxyWithBaseURL()
{
HttpWebRequest webReq =(HttpWebRequest)WebRequest.Create(http: //www.finra.org/);
CookieContainer cookieContainer = new CookieContainer();
string res;
try
{
webReq.Method =GET;
//webReq.Proxy = wp;
webReq.CookieContainer = cookieContainer;
//webReq.MaximumAutomaticRedirections = 10000;
using(WebResponse response = webReq.GetResponse ())
{
使用(Stream stream = response.GetResponseStream())
{
StreamReader阅读器= new StreamReader(stream);
res = reader.ReadToEnd();
}
}
webReq =(HttpWebRequest)WebRequest.Create(http://tsp.finra.o rg / finra_org / ticksizepilot / TSPrePilotSecurities.txt);
webReq.CookieContainer = cookieContainer;
webReq.Method =GET;
WebProxy wp = new WebProxy(http://SomeProxy.pac);
webReq.Proxy = wp;
using(WebResponse response2 = webReq.GetResponse())
{
使用(Stream stream = response2.GetResponseStream())
{
StreamReader reader = new StreamReader (流);
res = reader.ReadToEnd();
}
}
File.AppendAllText(pilotSecuritiesFilePath,res);
LogMessage(使用带有基本URL的代理的WebRequest下载:已完成);
}
catch(Exception ex)
{
LogMessage(使用带有基本URL的代理的WebRequest下载:错误+ ex.Message);
}
}
}
}
Hi,
I am trying to download the belo URLs
[^]
[^]
I am able to download the above URLs with out mentioning the Proxy.
If I set the proxy I am getting the error message "Error Too many automatic redirections were attempted" .
Please let me know if you need more inforamtion.
Thanks,
Siddi.
What I have tried:
Below are the different options I have tried:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
namespace AutoRedirect
{
class Program
{
static string pilotSecuritiesFilePath = @"C:\FINRA\pilotSecuritiesProxy.txt";//GetPilotSecuritiesFilePath();
static string pilotChangesFilePath = @"C:\FINRA\pilotChangesProxy.txt";//GetPilotChangesFilePath();
static string masterURL = "http://tsp.finra.org/finra_org/ticksizepilot/TSPrePilotSecurities.txt";
static string changeURL = "http://tsp.finra.org/finra_org/ticksizepilot/TSPrePilotChanges.txt";
static string sSource;
static string sLog;
static string sEvent;
static string filePath = @"C:\FINRA\Log.txt";
static void Main(string[] args)
{
sSource = "AutoRedirectApp";
sLog = "Application";
sEvent = "AutoRedirect";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
//if (!EventLog.SourceExists(sSource))
// EventLog.CreateEventSource(sSource, sLog);
DownloadPilotSecuritiesWithoutProxy();
DownloadPilotSecurities();
DownloadUsingWebRequestWithoutProxy();
DownloadUsingWebRequestWithProxy();
DownloadUsingWebRequestWithProxyMaxRedirections();
DownloadUsingWebRequestWithProxyWithBaseURL();
}
private static void DownloadPilotSecuritiesWithoutProxy()
{
//LogMessage("Download using WebClient Without Proxy: Start");
try
{
using (WebClient webClient = new WebClient())
{
//webClient.BaseAddress = "http://www.finra.org/";
webClient.DownloadFile(masterURL, pilotSecuritiesFilePath);
webClient.DownloadFile(changeURL, pilotChangesFilePath);
}
}
catch (Exception ex)
{
EventLog.WriteEntry(sSource, ex.Message);
//LogMessage(ex.Message);
LogMessage("Download using WebClient Without Proxy: Error " + ex.Message);
}
LogMessage("Download using WebClient Without Proxy: Completed");
}
private static void DownloadPilotSecurities()
{
// LogMessage("Download using WebClient with Proxy: Started");
try
{
using (WebClient webClient = new WebClient())
{
WebProxy wp = new WebProxy("http://SomeProxy.pac");
webClient.Proxy = wp;
//webClient.BaseAddress = "http://www.finra.org/";
webClient.DownloadFile(masterURL, pilotSecuritiesFilePath);
webClient.DownloadFile(changeURL, pilotChangesFilePath);
}
LogMessage("Download using WebClient with Proxy: Completed");
}
catch (Exception ex)
{
//EventLog.WriteEntry(sSource, ex.Message);
Console.WriteLine(ex.Message);
//LogMessage(ex.Message);
LogMessage("Download using WebClient with Proxy: Error " + ex.Message);
}
}
private static void DownloadUsingWebRequestWithoutProxy()
{
// LogMessage("Download Using WebRequest without Proxy: Started");
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(masterURL);
string res;
try
{
webReq.Method = "GET";
using (WebResponse response = webReq.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd();
}
}
File.AppendAllText(pilotSecuritiesFilePath, res);
LogMessage("Download Using WebRequest without Proxy: Completed");
}
catch (Exception ex)
{
LogMessage("Download Using WebRequest without Proxy: Error " + ex.Message);
}
}
private static void DownloadUsingWebRequestWithProxy()
{
// LogMessage("Download Using WebRequest without Proxy: Started");
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(masterURL);
CookieContainer cookieContainer = new CookieContainer();
string res;
try
{
webReq.Method = "GET";
WebProxy wp = new WebProxy("http://SomeProxy.pac");
webReq.Proxy = wp;
webReq.CookieContainer = cookieContainer;
using (WebResponse response = webReq.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd();
}
}
File.AppendAllText(pilotSecuritiesFilePath, res);
LogMessage("Download Using WebRequest with Proxy: Completed");
}
catch (Exception ex)
{
LogMessage("Download Using WebRequest with Proxy: Error " + ex.Message);
}
}
private static void DownloadUsingWebRequestWithProxyMaxRedirections()
{
// LogMessage("Download Using WebRequest without Proxy: Started");
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(masterURL);
CookieContainer cookieContainer = new CookieContainer();
string res;
try
{
webReq.Method = "GET";
WebProxy wp = new WebProxy("http://SomeProxy.pac");
webReq.Proxy = wp;
webReq.CookieContainer = cookieContainer;
webReq.MaximumAutomaticRedirections = 10000;
using (WebResponse response = webReq.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd();
}
}
File.AppendAllText(pilotSecuritiesFilePath, res);
LogMessage("Download Using WebRequest with Proxy with Max Redirections: Completed");
}
catch (Exception ex)
{
LogMessage("Download Using WebRequest with Proxy with Max Redirections: Error " + ex.Message);
}
}
private static void LogMessage(string message)
{
File.AppendAllText(filePath, Environment.NewLine+message);
}
private static void DownloadUsingWebRequestWithProxyWithBaseURL()
{
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create("http://www.finra.org/");
CookieContainer cookieContainer = new CookieContainer();
string res;
try
{
webReq.Method = "GET";
//webReq.Proxy = wp;
webReq.CookieContainer = cookieContainer;
//webReq.MaximumAutomaticRedirections = 10000;
using (WebResponse response = webReq.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd();
}
}
webReq = (HttpWebRequest)WebRequest.Create("http://tsp.finra.org/finra_org/ticksizepilot/TSPrePilotSecurities.txt");
webReq.CookieContainer = cookieContainer;
webReq.Method = "GET";
WebProxy wp = new WebProxy("http://SomeProxy.pac");
webReq.Proxy = wp;
using(WebResponse response2 = webReq.GetResponse())
{
using (Stream stream = response2.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd();
}
}
File.AppendAllText(pilotSecuritiesFilePath, res);
LogMessage("Download Using WebRequest with Proxy with Base URL: Completed");
}
catch (Exception ex)
{
LogMessage("Download Using WebRequest with Proxy with Base URL : Error " + ex.Message);
}
}
}
}
推荐答案
Hi More information can be found at the below URLs:
使用PAC文件代理
代理无法下载文件在WebClient或HttpWebRequest中提到 [ ^ ]
谢谢,
Siddi。
Using PAC files proxy
Unable to download a file when proxy is mentioned in WebClient or HttpWebRequest[^]
Thanks,
Siddi.
这篇关于无法使用代理下载URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!