One, the Ink interface call
PrivateString host = configurationmanager.appsettings["Weatherhost"]; Private ConstString Pathweather ="/whapi/json/alicityweather/briefforecast3days"; Private ConstString method ="POST"; PrivateString Appcode = configurationmanager.appsettings["Weatherappcode"]; Private ConstString Pathaqi ="/whapi/json/alicityweather/briefaqi"; Private stringGetweatheroraqi (stringPathintCityid =2) {String Querys=""; String Bodys="cityid="+Cityid; //String bodys = "CITYID=2&TOKEN=677282C2F1B3D718152C4E25ED434BC4";//_ZXString URL = host +path; HttpWebRequest HttpRequest=NULL; HttpWebResponse HttpResponse=NULL; if(0<Querys. Length) {URL= URL +"?"+Querys; } if(host. Contains ("https://") ) {Servicepointmanager.servercertificatevalidationcallback=NewRemotecertificatevalidationcallback (CheckValidationResult); HttpRequest= (HttpWebRequest) Webrequest.createdefault (NewUri (URL)); } Else{HttpRequest=(HttpWebRequest) webrequest.create (URL); } Httprequest.method=method; HTTPREQUEST.HEADERS.ADD ("Authorization","Appcode"+Appcode); //According to the requirements of the API, define the corresponding Content-typeHttprequest.contenttype ="application/x-www-form-urlencoded; Charset=utf-8"; if(0<Bodys. Length) {byte[] data =Encoding.UTF8.GetBytes (bodys); using(Stream stream =Httprequest.getrequeststream ()) {stream. Write (data,0, data. Length); } } Try{HttpResponse=(HttpWebResponse) httprequest.getresponse (); } Catch(WebException ex) {HttpResponse=(HttpWebResponse) ex. Response; } //Console.WriteLine (Httpresponse.statuscode); //Console.WriteLine (Httpresponse.method); //Console.WriteLine (httpresponse.headers);Stream st =Httpresponse.getresponsestream (); StreamReader Reader=NewStreamReader (St, Encoding.GetEncoding ("Utf-8")); returnReader. ReadToEnd (); } Public Static BOOLCheckValidationResult (Objectsender, X509Certificate certificate, X509chain chain, sslpolicyerrors errors) { return true; }
View Code
C # Fetch Ink calls Ink weather interface save to database