程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> ASP.NET基礎 >> 解決iis7.5服務器上.net 獲取不到https頁面的信息

解決iis7.5服務器上.net 獲取不到https頁面的信息

編輯:ASP.NET基礎

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved