C # calls Wild Dog cloud REST API

Source: Internet
Author: User

Wild Dog Cloud is not much introduced, here is mainly to record the C # call them to provide the rest API, the data post to the Wild Dog cloud storage, directly on the code

Static voidMain (string[] args) {            stringstr ="Hello"; /** Note the link here to add. JSON * I was here in the pit for 1 hours. * Always exception: After the bad Request * I am in the Wild Dog cloud application Manually added a user node * and then saved as normal.*/            //appId: Corresponding to your wild Dog cloud appPost ("Https://<appId>.wilddogio.com/user.json","{\ "col1\": \ ""+ DateTime.Now.ToString ("YYYY/MM/DD HH:mm:ss") +"\ ", \" col2\ ": \""+ str +"\"}"); }        /// <summary>        ///send a POST request/// </summary>        /// <param name= "PostURL" >Request Address</param>        /// <param name= "Jsonstr" >JSON data</param>        /// <returns></returns>         Public Static stringPost (stringPostURL,stringjsonstr) {            //Set HTTPS authentication mode            if(PostURL. StartsWith ("HTTPS", StringComparison.OrdinalIgnoreCase)) {Servicepointmanager.servercertificatevalidationcallback=NewRemotecertificatevalidationcallback (CheckValidationResult); } HttpWebRequest Request=(HttpWebRequest) webrequest.create (PostURL); Request. Method="POST"; Request. ContentType="application/x-www-form-urlencoded"; //JSON string to byte array            byte[] bytes =System.Text.Encoding.UTF8.GetBytes (JSONSTR); //set the contentlength of the requestRequest. ContentLength =bytes.            Length; //send request, GET request streamStream stream; Try            {                //gets the stream object used to write the request datastream =request.            GetRequestStream (); }            Catch(Exception ex) {stream=NULL; Console.WriteLine (ex.            Message); }            //write data to a streamStream. Write (Bytes,0, Bytes.            Length); Stream.            Close ();            HttpWebResponse response; Try            {                //get the response streamResponse =(HttpWebResponse) request.            GetResponse (); }            Catch(WebException ex) {response= ex. Response asHttpWebResponse; } Stream S=Response.            GetResponseStream (); StreamReader SR=NewStreamReader (S, Encoding.UTF8); stringStrval =Sr. ReadToEnd ().            Trim (); Sr.            Close ();            S.close (); returnStrval; }         Public Static BOOLCheckValidationResult (Objectsender, X509Certificate certificate, X509chain chain, sslpolicyerrors errors) {            return true; }

Wild Dog Cloud app Configure a bit of byte point

Post successful return

Write for the first time, just make a record, and also hope to help the people who need help.

C # calls Wild Dog cloud REST API

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.