C # Fetch Ink calls Ink weather interface save to database

Source: Internet
Author: User

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

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.