public static string SendRequest(HttpRequestUtility.RequestEntity req) { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(req.Url); httpWebRequest.Headers.Clear(); if (!string.IsNullOrEmpty(req.ProxyIp)) { httpWebRequest.Proxy = new WebProxy(req.ProxyIp); } if (req.Credential != null) { httpWebRequest.Credentials = req.Credential; } httpWebRequest.Method = req.RequestType; if (req.ContentType != null) { httpWebRequest.ContentType = req.ContentType; } if (req.RequestData != null) { httpWebRequest.ContentLength = (long)req.RequestData.Length; using (Stream requestStream = httpWebRequest.GetRequestStream()) { requestStream.Write(req.RequestData, 0, req.RequestData.Length); } } string result; try { using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse()) { using (Stream responseStream = httpWebResponse.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { result = streamReader.ReadToEnd(); } } } } catch (WebException ex) { using (Stream responseStream2 = ex.Response.GetResponseStream()) { using (StreamReader streamReader2 = new StreamReader(responseStream2)) { result = streamReader2.ReadToEnd(); } } } return(result); }
public static string Get(HttpRequestUtility.RequestEntity req) { return(HttpRequestUtility.SendRequest(req)); }