我遇到問題,我的代碼等待很長一段時間 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
我在做什麼錯了?有時我會從我的隊列中弄到不好的代理,所以我想能夠超時並跳過。等待GET回覆
Boolean match = false;
String clean = String.Empty;
String msbuff;
IWebProxy insideProxy;
try
{
//grab proxies based on queue
String proxyQueItem = Proxy_Que(_rankingConnectionString);
insideProxy = new WebProxy(proxyQueItem);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(ResultURL);
request.Proxy = insideProxy;
request.Timeout = 15*1000;
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
{
if (response.StatusCode == HttpStatusCode.OK)
{
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
msbuff = streamRead.ReadToEnd();
//get rid of , -, (,)
msbuff = msbuff.Replace(" ", String.Empty).Replace(" ", String.Empty);
msbuff = msbuff.Replace("-", String.Empty);
msbuff = msbuff.Replace("(", String.Empty);
msbuff = msbuff.Replace(")", String.Empty);
//attempt to find phone number
match = msbuff.Contains(Listing.PhoneNumber);
streamRead.Close();
}
}
}
catch (Exception lk)
{ }
您沒有使用[WebClient](http://msdn.microsoft.com/zh-cn/library/system.net.webclient.aspx)(.NET 1.1 - 4.0)或[HttpClient]( http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx)(.NET 4.5)? – dtb
我也試過WebClient,它會在客戶端上等待。downloadString –
您是否在問一個特定的錯誤,如果是,錯誤是什麼?或者你是否要求提供有關流量控制的建議,以便跳到隊列中的下一個代理? –