资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Howtogethttpresponse.-创新互联

成都创新互联公司服务项目包括高明网站建设、高明网站制作、高明网页制作以及高明网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,高明网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到高明省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!>public class HttpWebResponseUtility { public static string CreateGetHttpResponse(string url) { var response = CreateGetHttpResponse(url, null); Stream dataStream= response.GetResponseStream(); StreamReader reader= new StreamReader(dataStream); string responseString = reader.ReadToEnd(); return responseString; } public static string CreatePostHttpResponse(string url, IDictionary parameters) { var response = CreatePostHttpResponse(url, parameters,null,System.Text.Encoding.UTF8); Stream dataStream= response.GetResponseStream(); StreamReader reader= new StreamReader(dataStream); string responseString = reader.ReadToEnd(); return responseString; } public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } var request = WebRequest.Create(url) as HttpWebRequest; request.Method= "GET"; request.Proxy= null; request.Credentials= CredentialCache.DefaultCredentials; //allows for validation of SSL certificates ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); if (timeout.HasValue) { request.Timeout= timeout.Value; } return request.GetResponse() as HttpWebResponse; } public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary parameters, int? timeout, Encoding requestEncoding) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } if (requestEncoding == null) { throw new ArgumentNullException("requestEncoding"); } HttpWebRequest request= null; if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) { ServicePointManager.ServerCertificateValidationCallback= new RemoteCertificateValidationCallback(CheckValidationResult); request= WebRequest.Create(url) as HttpWebRequest; request.Proxy= null; request.Credentials= CredentialCache.DefaultCredentials; request.ProtocolVersion= HttpVersion.Version10; } else { request= WebRequest.Create(url) as HttpWebRequest; } request.Method= "POST"; request.ContentType= "application/x-www-form-urlencoded"; if (timeout.HasValue) { request.Timeout= timeout.Value; } if (!(parameters == null || parameters.Count == 0)) { StringBuilder buffer= new StringBuilder(); int i = 0; foreach (string key in parameters.Keys) { if (i > 0) { buffer.AppendFormat("&{0}={1}", key, parameters[key]); } else { buffer.AppendFormat("{0}={1}", key, parameters[key]); } i++; } byte[] data = requestEncoding.GetBytes(buffer.ToString()); using (Stream stream = request.GetRequestStream()) { stream.Write(data,0, data.Length); } } return request.GetResponse() as HttpWebResponse; } private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; //总是接受 } }
分享文章:Howtogethttpresponse.-创新互联
本文来源:http://www.cdkjz.cn/article/ceshjh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220