/// <summary> /// Builds a HTTP request from the given arguments. /// </summary> /// <param name="url">The URL.</param> /// <param name="verb">The verb.</param> /// <param name="agent">The agent.</param> /// <param name="cookies">The cookies.</param> /// <param name="referer">The referer.</param> /// <param name="retries">The retries.</param> /// <param name="timeout">The timeout.</param> /// <param name="accept">The accept.</param> /// <param name="encoding">The encoding.</param> /// <returns></returns> public HttpRequest Build(string url, HttpVerb verb , string agent, CookieContainer cookies = null, string referer = "", int retries = 0, int timeout = 10000, BaseMime accept = null, Encoding encoding = null) { var request = new HttpRequest { Url = url, UserAgent = agent, Verb = verb, Referer = referer, Retries = retries, Timeout = timeout, Encoding = encoding ?? Encoding.UTF8 }; if (accept != null) { request.Accept = accept.ToString(); } if (cookies != null) { request.Cookies = cookies; } return request; }
/// <summary> /// POSTs to the specified URL. /// </summary> /// <param name="url">The URL.</param> /// <param name="agent">The agent.</param> /// <param name="cookies">The cookies.</param> /// <param name="referer">The referer.</param> /// <param name="retries">The retries.</param> /// <param name="timeout">The timeout.</param> /// <param name="accept">The accept.</param> /// <param name="encoding">The encoding.</param> /// <returns></returns> public HttpResponse Post(string url, string agent, CookieContainer cookies = null, string referer = "", int retries = 0, int timeout = 10000, BaseMime accept = null, Encoding encoding = null) { return Download(url, HttpVerb.Post, agent, cookies, referer, retries, timeout, accept, encoding); }
/// <summary> /// Downloads the specified URL. /// </summary> /// <param name="url">The URL.</param> /// <param name="verb">The verb.</param> /// <param name="agent">The agent.</param> /// <param name="cookies">The cookies.</param> /// <param name="referer">The referer.</param> /// <param name="retries">The retries.</param> /// <param name="timeout">The timeout.</param> /// <param name="accept">The accept.</param> /// <param name="encoding">The encoding.</param> /// <returns></returns> /// <remarks> /// Will retry to download 3 times by default. /// </remarks> public HttpResponse Download(string url, HttpVerb verb, string agent, CookieContainer cookies = null, string referer = "", int retries = 0, int timeout = 10000, BaseMime accept = null, Encoding encoding = null) { var request = Build(url, verb, agent, cookies, referer, retries, timeout, accept, encoding); return Download(request); }