• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

解决iis7.5服务器上.net 获取不到https页面的信息

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

我的获取页面需要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;
        }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
asp.net Xml绑定到数据控件的具体实现发布时间:2022-02-05
下一篇:
MVC 5 第一章 创建MVC 5 web应用程序发布时间:2022-02-05
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap