Solution: the. net Server on iis7.5 cannot obtain the https page information

Source: Internet
Author: User

I need cookies to retrieve pages. If I do not need them, I can remove them;

GET method:

Copy codeThe Code is as follows:
/// <Summary>
/// Obtain the HTML content accessed by the URL
/// </Summary>
/// <Param name = "Url"> URL </param>
/// <Returns> HTML content </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 method:

Copy codeThe Code is as follows:
/// <Summary>
/// Post submit data to 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;
// Submit the request
Stream stream;
Stream = request. GetRequestStream ();
Stream. Write (postdatabyte, 0, postdatabyte. Length );
Stream. Close ();
// Receive response
Response = (HttpWebResponse) request. GetResponse ();
Using (StreamReader reader = new StreamReader (response. GetResponseStream ()))
{
Restr = reader. ReadToEnd (). ToString ();
}
Return restr;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.