public FinalData(string uri) { ResponseData = new ResponseData(uri); }
public static ResponseData HTTP(string method, string url, string POST_Data_string, bool Foloredi = false) { ResponseData resData = new ResponseData(url); if (url.StartsWith("http://") == false) { if (url.StartsWith("https://") == false) { url = "http://" + url; } } resData.FirstUrl = url; if (url.Replace("http://", "").Length < 5 || url.Replace("https", "").Length < 5) { return(resData); } try { url = url.Replace(' ', '+'); var reeq = (HttpWebRequest)WebRequest.Create(url); reeq.UserAgent = User_Agents[Program.GetRandomInt(User_Agents.Count)]; reeq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; reeq.Headers.Add("accept-language", "en-US,en;q=0.5"); reeq.Referer = url; reeq.Method = "GET"; if (method.ToLower() == "post") { reeq.Method = "POST"; var POST_data = Encoding.ASCII.GetBytes(POST_Data_string); reeq.ContentLength = POST_data.Length; reeq.ContentType = "application/x-www-form-urlencoded"; using (var strm = reeq.GetRequestStream()) { strm.Write(POST_data, 0, POST_data.Length); } } string cokstr = GetSiteStaticCookie(url); if (cokstr.Length > 2) { reeq.Headers.Add("cookies", cokstr); } //" r.Referer = url; reeq.AllowAutoRedirect = Foloredi; var resp = (HttpWebResponse)reeq.GetResponse(); resData.success = true; var text = new StreamReader(resp.GetResponseStream(), Encoding.UTF8).ReadToEnd(); resData.body = text; for (int i = 0; i < resp.Headers.Count; i++) { string key = "", val = ""; try { key = resp.Headers.GetKey(i); if (key.Length < 2) { continue; } val = resp.Headers[key].ToString(); if (key.ToLower().Trim() == "location") { resData.redirectedTo = val; } bool added = false; if (resData.Headers.ContainsKey(key)) { resData.Headers[key] += val; added = true; break; } else { resData.Headers.Add(key, val); } } catch { try { resData.Headers[key] = val; } catch { } } } Program.LastResponseData = resData; return(resData); } catch (Exception x) { resData.SetResponseError(x.Message); if (x.Message.Contains("The operation has timed out") || x.Message.Contains("Unable to connect to the remote server") || x.Message.Contains("The remote name could not be resolved")) { resData.errorcode = 0; resData.success = false; resData.ErrorUrl = url; resData.RequiresReplay = true; } else { try { var s = (x as System.Net.WebException).Response; var sc = s.GetResponseStream(); string body = new StreamReader(sc).ReadToEnd(); string responseMessageHeaders = "HTTP/1.1 " + (resData.errorcode) + " " + "\n"; for (int i = 0; i < s.Headers.Count; i++) { try { string k = s.Headers.GetKey(i); string v = s.Headers[k]; responseMessageHeaders += k + ": " + v + "\n"; resData.Headers.Add(k, v); } catch { } } resData.body = body; resData.ResponseHeaders = responseMessageHeaders; resData.HasError = true; resData.SetResponseError(x.Message); } catch (Exception xsa) { resData.HasError = true; resData.ResponseErrorMessage = (xsa.Message); } } } return(resData); }