An example of taking data online

xiaoxiao2021-03-06  135

private void Page_Load (object sender, System.EventArgs e) {string url = "http: //localhost/webUserWindowExample/WebForm5.aspx"; System.Net .CookieContainer cook = new System.Net .CookieContainer (); string gets = getHTMLByUrlCook (URL, REF COOK, "GET", NULL, TRUE); string str refreadState = system.text .regularexpressions .regEX.Replace (Gets, "[// s * // s *] *

public string getHTMLByUrlCook (string url, ref System.Net.CookieContainer cook, string sMethod, string Param, bool bAutoRedirect) {sMethod = sMethod.ToUpper (); sMethod = sMethod = "POST" "GET":!? sMethod; string res = ""; HttpWebRequest re = (HttpWebRequest) HttpWebRequest.Create (url); re.CookieContainer = cook; // attach the cook object re.Method = sMethod; // re.AllowAutoRedirect = bAutoRedirect; // re.UserAgent = " Mozilla / 4.0 (compatible; msie 6.0; windows NT 5.2; myie2; .NET CLR 1.1.4322) "; //

//re.ClientCertificates = new System.Security.Cryptography.X509Certificates.X509CertificateCollection (); //re.ClientCertificates = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile ();

//re.timeout = 2000; if (SMETHOD == "post") // post data to server {re.contenttype = "Application / X-www-form-urlencoded"; byte [] b = system.text.encoding .Utf8.GetBytes (param); Re.ContentLength = B.LENGTH; try {stream osre = re.getRequestStream (); OSRE.WRITE (B, 0, B.LENGTH); OSRE.CLOSE (); osre = null; } catch (Exception) {re = null; return "-1";}} HttpWebResponse rep = null; Stream oResponseStream = null; StreamReader oSReader = null; try {rep = (HttpWebResponse) re.GetResponse (); oResponseStream = rep. GetResponseStream (); oSReader = new StreamReader (oResponseStream, System.Text.Encoding.Default); res = oSReader.ReadToEnd ();} catch (System.Net.WebException e) {// res = "- 1"; res = e.tostring ();} if (rep! = null) {rep.close (); rep = null;} if (OresponseStream! = null) {OresponseStream.close (); oresponsestream = null; or osReader! = NULL) {osreader.close (); Osreader = null;} re = null;

Return res;}

转载请注明原文地址:https://www.9cbs.com/read-127291.html

New Post(0)