1 Private Static stringGETURL (stringURL)2 {3HttpWebRequest request =NULL;4 if(URL.) StartsWith ("HTTPS", stringcomparison.ordinalignorecase))5 {6Request = WebRequest.Create (URL) asHttpWebRequest;7Servicepointmanager.servercertificatevalidationcallback =NewRemotecertificatevalidationcallback (checkvalidationresult);8Request. ProtocolVersion =httpversion.version11;9 //the protocol type is set here. TenServicepointmanager.securityprotocol = (securityprotocoltype)3072;//securityprotocoltype.tls1.2; OneRequest. KeepAlive =false; AServicepointmanager.checkcertificaterevocationlist =true; -Servicepointmanager.defaultconnectionlimit = -; -Servicepointmanager.expect100continue =false; the } - Else - { -Request =(HttpWebRequest) webrequest.create (URL); + } - +Request. Method ="GET";//send data using get mode ARequest. ContentType ="application/x-www-form-urlencoded"; atRequest. Referer =NULL; -Request. AllowAutoRedirect =true; -Request. UserAgent ="mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2;. NET CLR 1.1.4322;. NET CLR 2.0.50727)"; -Request. Accept ="*/*"; - - //byte[] data = Encoding.UTF8.GetBytes (postdata); in //Stream newstream = Request. GetRequestStream (); - //newstream.write (data, 0, data. Length); to //newstream.close (); + - //get Web page response Results theHttpWebResponse response =(HttpWebResponse) request. GetResponse (); *Stream stream =Response. GetResponseStream (); $ //client. Headers.add ("Content-type", "application/x-www-form-urlencoded");Panax Notoginseng stringresult =string. Empty; - using(StreamReader sr =NewStreamReader (stream)) the { +result =Sr. ReadToEnd (); A } the + returnresult; - } $ $ Private Static stringPostURL (stringUrlstringpostdata) - { -HttpWebRequest request =NULL; the if(URL.) StartsWith ("HTTPS", stringcomparison.ordinalignorecase)) - {WuyiRequest = WebRequest.Create (URL) asHttpWebRequest; theServicepointmanager.servercertificatevalidationcallback =NewRemotecertificatevalidationcallback (checkvalidationresult); -Request. ProtocolVersion =httpversion.version11; Wu //the protocol type is set here. -Servicepointmanager.securityprotocol = (securityprotocoltype)3072;//securityprotocoltype.tls1.2; AboutRequest. KeepAlive =false; $Servicepointmanager.checkcertificaterevocationlist =true; -Servicepointmanager.defaultconnectionlimit = -; -Servicepointmanager.expect100continue =false; - } A Else + { theRequest =(HttpWebRequest) webrequest.create (URL); - } $ theRequest. Method ="POST"; theRequest. ContentType ="application/x-www-form-urlencoded"; theRequest. Referer =NULL; theRequest. AllowAutoRedirect =true; -Request. UserAgent ="mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2;. NET CLR 1.1.4322;. NET CLR 2.0.50727)"; inRequest. Accept ="*/*"; the the byte[] data =Encoding.UTF8.GetBytes (postdata); AboutStream newstream =request. GetRequestStream (); theNewstream.write (data,0, data. Length); the newstream.close (); the + //get Web page response Results -HttpWebResponse response =(HttpWebResponse) request. GetResponse (); theStream stream =Response. GetResponseStream ();Bayi //client. Headers.add ("Content-type", "application/x-www-form-urlencoded"); the stringresult =string. Empty; the using(StreamReader sr =NewStreamReader (stream)) - { -result =Sr. ReadToEnd (); the } the the returnresult; the } - the Private Static BOOLCheckValidationResult (Objectsender, X509Certificate certificate, X509chain chain, sslpolicyerrors errors) the { the return true;//Always accept94}View Code
C # Request HTTPS