足球游戏_中国足彩网¥体育资讯$

解决iis7.5服务器上.net 获取不到https页面的信息
来源:易贤网 阅读:942 次 日期:2014-08-04 15:20:01
温馨提示:易贤网小编为您整理了“解决iis7.5服务器上.net 获取不到https页面的信息”,方便广大网友查阅!

让我纠结了一天多的问题,给大家看下,有相同情况的可以不用浪费时间了,本人当时找了好半天都没找到什么有用的信息,项目在本地没有问题,但部署在服务器后,获取不到https页面的信息,加入下面的代码就可以了,因为iis7.5的安全协议比较高的原因。

我的获取页面需要cookie,不需要的可以去掉;

GET的方法:

代码如下:

/// <summary>

        /// 获取URL访问的HTML内容 获取https 页面的

        /// </summary>

        /// <param name="Url">URL地址</param>

        /// <returns>HTML内容</returns>

        public static string GetWebContent(string Url, CookieContainer cookieContainer)

        {

            string strResult = "";

            try

            {

                ServicePointManager.Expect100Continue = true;

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

                request.CookieContainer = cookieContainer;

                request.Timeout = 30000;

                request.Headers.Set("Pragma", "no-cache");

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                Stream streamReceive = response.GetResponseStream();

                Encoding encoding = Encoding.GetEncoding("utf-8");

                StreamReader streamReader = new StreamReader(streamReceive, encoding);

                strResult = streamReader.ReadToEnd();

            }

            catch

            {

            }

            return strResult;

        }

 POST的方法:

代码如下:

/// <summary>

        /// post提交数据到https

        /// </summary>

        /// <param name="posturl"></param>

        /// <param name="postdata"></param>

        /// <param name="header"></param>

        /// <param name="cookieContainer"></param>

        /// <returns></returns>

        public static string SetPostHtml(string posturl, string postdata, HttpHeader header, CookieContainer cookieContainer)

        {

            string restr = "";

            ServicePointManager.Expect100Continue = true;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

            HttpWebRequest request = null;

            HttpWebResponse response = null;

            request = (HttpWebRequest)WebRequest.Create(posturl);

            request.CookieContainer = cookieContainer;

            request.Method = header.method;

            request.Referer = header.Referer;

            request.ContentType = header.contentType;

            byte[] postdatabyte = Encoding.UTF8.GetBytes(postdata);

            request.ContentLength = postdatabyte.Length;

            request.AllowAutoRedirect = false;

            request.KeepAlive = true;

            //提交请求

            Stream stream;

            stream = request.GetRequestStream();

            stream.Write(postdatabyte, 0, postdatabyte.Length);

            stream.Close();

            //接收响应

            response = (HttpWebResponse)request.GetResponse();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))

            {

                restr = reader.ReadToEnd().ToString();

            }

            return restr;

        }

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看网络编程
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标