using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; namespace ICSSoft.Frame.Data.DAL { public class CustWebRequest { public static string WorkDayPostData(string URL, string JsonData, string ContentType) { string str = string.Empty; try { WebRequest request = WebRequest.Create(URL); request.Method = "POST"; byte[] bytes = System.Text.Encoding.UTF8.GetBytes(JsonData); request.ContentType = ContentType; request.ContentLength = bytes.Length; using (Stream postStream = request.GetRequestStream()) { postStream.Write(bytes, 0, bytes.Length); } request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = null; try { response = request.GetResponse(); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) response = (WebResponse)ex.Response; } if (response != null) { using (StreamReader st = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8)) { str = System.Web.HttpUtility.UrlDecode(st.ReadToEnd()); } } } catch (Exception ex) { str = ex.Message; } return str; } public static string WebRequestGetData(string URL) { WebRequest request = WebRequest.Create(URL); request.Method = "GET"; request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"; request.Credentials = CredentialCache.DefaultCredentials; string str = string.Empty; WebResponse response = null; try { response = request.GetResponse(); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) response = (WebResponse)ex.Response; } if (response != null) { using (StreamReader st = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8)) { str = System.Web.HttpUtility.UrlDecode(st.ReadToEnd()); } } return str; } } }