private static HttpHelp HttpMethod(string url, string ContentType, Encoding encoding, CookieCollection cookies, StringBuilder data) { try { HttpWebRequest web = (HttpWebRequest)System.Net.WebRequest.Create(url); web.ContentType = ContentType == string.Empty ? "application/x-www-form-urlencoded" : ContentType; web.Method = "POST"; web.CookieContainer = new CookieContainer(); if (cookies != null) { foreach (Cookie c in cookies) { web.CookieContainer.Add(c); } } web.AllowAutoRedirect = false; web.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"; byte[] byteArray = encoding.GetBytes(data.ToString()); web.ContentLength = byteArray.Length; Stream newStream = web.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); newStream.Close(); HttpHelp response = new HttpHelp() { _Response = (HttpWebResponse)web.GetResponse() }; return(response); } catch (Exception ee) { throw new Exception(ee.Message, ee); } }
public static HttpHelp GetRequest(string url, string ContentType) { HttpWebRequest web = (HttpWebRequest)System.Net.WebRequest.Create(url); web.ContentType = ContentType == string.Empty ? "text/html; charset=UTF-8" : ContentType; web.Method = "GET"; web.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"; var response = new HttpHelp() { _Response = (HttpWebResponse)web.GetResponse() }; return(response); }
public static HttpHelp PostRequest(string url, string ContentType, string data, Encoding encoding) { HttpWebRequest web = (HttpWebRequest)System.Net.WebRequest.Create(url); web.ContentType = ContentType == string.Empty ? "application/x-www-form-urlencoded" : ContentType; web.CookieContainer = new CookieContainer(); web.Method = "POST"; web.AllowAutoRedirect = false; web.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"; byte[] byteArray = encoding.GetBytes(data); web.ContentLength = byteArray.Length; Stream newStream = web.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); newStream.Close(); HttpHelp response = new HttpHelp() { _Response = (HttpWebResponse)web.GetResponse() }; return(response); }