private static WebResponse GetRespByExecuteRequest(string url, HttpContentType type, object data, HttpMethod method) { try { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.ContentType = type.ToString(); req.Method = method.ToString(); if (method != HttpMethod.GET) { string strData = string.Empty; strData = ParamGeneratorFactory.GetParamGenerator(type).GetParamString(data); byte[] postBytes = Encoding.UTF8.GetBytes(strData); req.ContentLength = postBytes.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(postBytes, 0, postBytes.Length); } } return(req.GetResponse()); } catch (Exception e) { throw e; } }
private static string ExecuteRequest(string url, HttpContentType type, object data, HttpMethod method, int timeOut = 100000) { try { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.ContentType = type.ToString(); req.Method = method.ToString(); req.Timeout = timeOut; if (method != HttpMethod.GET) { string strData = string.Empty; strData = ParamGeneratorFactory.GetParamGenerator(type).GetParamString(data); byte[] postBytes = Encoding.UTF8.GetBytes(strData); req.ContentLength = postBytes.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(postBytes, 0, postBytes.Length); } } using (WebResponse wr = req.GetResponse()) { using (StreamReader sr = new StreamReader(wr.GetResponseStream())) { return(sr.ReadToEnd()); } } } catch (Exception e) { throw e; } }