Public classHttpclienthelper { Public Static stringPost (stringUrlstringparamdata) { returnPost (URL, paramdata, Encoding.UTF8); } Public Static stringPost (stringUrlstringParamdata, Encoding Encoding) { stringresult =string. Empty; if(URL.) ToLower (). IndexOf ("HTTPS", System.StringComparison.Ordinal) >-1) {Servicepointmanager.servercertificatevalidationcallback=NewRemotecertificatevalidationcallback (sender, certificate, chain, errors) = {return true; }); } Try { varWC =NewWebClient (); if(string. IsNullOrEmpty (WC. headers["Content-type"]) WC. Headers.add ("Content-type","application/x-www-form-urlencoded"); Wc. Encoding=encoding; Result= WC. Uploadstring (URL,"POST", Paramdata); } Catch(Exception e) {stringExceptcontent = E.message.tostring (). Replace ("\"",""). Replace ("'",""); Weixinlog.writexceptionlog ("Httpclienthelper.post","url#"+ URL +"#paramData"+paramdata); } returnresult; } Public Static stringGet (stringURL) { returnGet (URL, Encoding.UTF8); } Public Static stringGet (stringURL, Encoding Encoding) { Try { varWC =NewWebClient {Encoding =encoding}; varReadstream =WC. OpenRead (URL); using(varSR =NewStreamReader (Readstream, encoding)) { varresult =Sr. ReadToEnd (); returnresult; } } Catch(Exception e) {Throwe; } } }
ASP. NET Post/get Public method