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://bzwzjz.com/article/ceshjh.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 温江网站设计 成都响应式网站建设公司 成都网站设计 成都营销网站制作 教育网站设计方案 营销型网站建设 宜宾网站设计 网站建设 品牌网站建设 成都网站建设 成都定制网站建设 重庆外贸网站建设 外贸网站建设 成都网站设计 成都网站制作 成都网站建设公司 成都网站制作 重庆网站建设 成都网站制作 定制网站制作 重庆网站设计 成都企业网站建设