解決iis7.5服務(wù)器上.net 獲取不到https頁(yè)面的信息
來(lái)源:易賢網(wǎng) 閱讀:1005 次 日期:2014-08-04 15:20:01
溫馨提示:易賢網(wǎng)小編為您整理了“解決iis7.5服務(wù)器上.net 獲取不到https頁(yè)面的信息”,方便廣大網(wǎng)友查閱!

讓我糾結(jié)了一天多的問(wèn)題,給大家看下,有相同情況的可以不用浪費(fèi)時(shí)間了,本人當(dāng)時(shí)找了好半天都沒(méi)找到什么有用的信息,項(xiàng)目在本地沒(méi)有問(wèn)題,但部署在服務(wù)器后,獲取不到https頁(yè)面的信息,加入下面的代碼就可以了,因?yàn)閕is7.5的安全協(xié)議比較高的原因。

我的獲取頁(yè)面需要cookie,不需要的可以去掉;

GET的方法:

代碼如下:

/// <summary>

        /// 獲取URL訪問(wèn)的HTML內(nèi)容 獲取https 頁(yè)面的

        /// </summary>

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

        /// <returns>HTML內(nèi)容</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提交數(shù)據(jù)到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;

            //提交請(qǐng)求

            Stream stream;

            stream = request.GetRequestStream();

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

            stream.Close();

            //接收響應(yīng)

            response = (HttpWebResponse)request.GetResponse();

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

            {

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

            }

            return restr;

        }

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:解決iis7.5服務(wù)器上.net 獲取不到https頁(yè)面的信息
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)