手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >解决iis7.5服务器上.net 获取不到https页面的信息
解决iis7.5服务器上.net 获取不到https页面的信息
摘要:我的获取页面需要cookie,不需要的可以去掉;GET的方法:复制代码代码如下://////获取URL访问的HTML内容获取https页面的...

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

}

【解决iis7.5服务器上.net 获取不到https页面的信息】相关文章:

asp.net xml序列化与反序列化第1/2页

asp.net post方法中参数取不出来的解决方法

asp.net传多个值到其它页面的具体实现

Asp.net 5种页面转向方法

asp.net下获取Excel所有的工作表名称

asp.net Google样式分页控件

ASP.NET 2.0服务器控件开发之复杂属性

asp.net跳转页面的三种方法比较

将Asp.Net网站发布到IIS的四种方法

asp.net 在DNN模块开发中遇到的resx怪问题

精品推荐
分类导航