HttpWebResponse GetResponse(
string requestUriString,
string proxyFile)
{
using (StreamReader reader = new StreamReader(proxyFile))
{
while (!reader.EndOfStream)
{
HttpWebRequest request =
WebRequest.Create(requestUriString)
as HttpWebRequest;
string address = reader.ReadLine();
try
{
request.Proxy = new WebProxy(address);
return request.GetResponse() as HttpWebResponse;
}
catch (System.Net.WebException)
{ }
}
}
throw new Exception("hello world!");
}
※ 引述《kyoin (nioyk)》之銘言:
: private void Form1_Load(object sender, EventArgs e)
: {
: StreamReader sr = new StreamReader(@"test.txt", System.Text.Encoding.Default);
: HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://tw.yahoo.com");
: try
: {
: // 這邊想寫 一行一行讀記事本
: request.Proxy = new WebProxy("放記事本第一行的proxy",port);
: HttpWebResponse webresponse =
: (HttpWebResponse)request.GetResponse();
: }
: catch (Exception e)
: {
: e.Message.ToString()="無法解析 Proxy 名稱:";
: }
: }
: 這隻程式的動作是先去讀取記事本
: 記事本的內容:
: proxy.hinet.net:80
: proxy.yahoo.com.tw:8132
: .
: .
: .
: .......
: 以此類推
: 然後在try當中先讀取第一行的文字
: 記事本每一行代表一個proxy
: 如果發生錯誤進入catch
: 如果錯誤的內容為無法解析 Proxy 名稱:
: 接著在進入try當中 讀取記事本的下一行
: 程式跑的動作大概就是這樣...
: 我遇到的問題
: 就是不曉得該怎麼讓記事本一行一行讀比較好
: 還有就是 如果遇到錯誤 該怎麼回去try當中讀取記事本的下一行
: 麻煩各位 給我一點提示了 謝謝!
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.161.41.122