/// <summary> /// A web method to return the response string from the URL. /// </summary> /// <param name="url">The URL to request.</param> /// <param name="method">The method to be used. Ex: POST</param> /// <param name="data">Dictionary containing the paramters to be sent in the URL or in the Stream, depending on the method.</param> /// <param name="cookies">A cookiecontainer with cookies to send.</param> /// <param name="xHeaders"> /// Special parameter, should only be used with requests that need "X-Requested-With: /// XMLHttpRequest" and "X-Prototype-Version: 1.7" /// </param> /// <param name="referer">Sets the referrer for the request.</param> /// <returns>A string from the response stream.</returns> public IResponse Fetch(string url, string method, Dictionary <string, string> data = null, CookieContainer cookies = null, bool xHeaders = true, string referer = "", bool isWebkit = false) { IResponse response = _webRequestHandler.HandleWebRequest(url, method, data, cookies, xHeaders, referer, isWebkit); return(response); }
/// <summary> /// Processes retry attempts /// </summary> /// <returns>IResponse interace.</returns> private IResponse RetryRequestProcessor(int retryWait, int retryLimit, string url, string method, Dictionary <string, string> data = null, CookieContainer cookies = null, bool xHeaders = true, string referer = "", bool isWebkit = false) { int attempts = 0; while (true) { try { return(_webRequestHandler.HandleWebRequest(url, method, data, cookies, xHeaders, referer, isWebkit)); } catch (WebException we) { HttpWebResponse response = we.Response as HttpWebResponse;; switch (we.Status) { case WebExceptionStatus.SendFailure: break; case WebExceptionStatus.ConnectFailure: break; case WebExceptionStatus.ConnectionClosed: break; case WebExceptionStatus.ReceiveFailure: break; case WebExceptionStatus.Timeout: break; case WebExceptionStatus.ProtocolError: break; default: if (response?.StatusCode == HttpStatusCode.NotFound) { return(null); } throw; } if (attempts >= retryLimit) { return(null); } attempts++; } Thread.Sleep(retryWait); } }