C # Call the wild dog cloud rest api,

Source: Internet
Author: User

C # Call the wild dog cloud rest api,

The wild dog cloud will not be introduced much. Here we will mainly record c # calling the rest api they provide, post the data to the wild dog cloud storage, and directly upload the code

 

Static void Main (string [] args) {string str = "hello";/** note that the link here must be added. json * I am stuck here for 1 hour * always exception: 400 Bad Request * I manually added a user node to the wild dog cloud application * And then saved it normally * // appId: corresponding to your wild dog cloud application Post ("https: // <appId> .wilddogio.com/user.json "," {\ "col1 \": \ "" + DateTime. now. toString ("yyyy/MM/dd HH: mm: ss") + "\", \ "col2 \": \ "" + str + "\"}");} /// <summary> /// send the post request /// </summary> /// <param name = "posturl"> request address </param> /// <param name = "jsonstr"> json data </param> // <returns> </returns> public static string Post (string posturl, string jsonstr) {// sets the https authentication method if (posturl. startsWith ("https", StringComparison. ordinalIgnoreCase) {ServicePointManager. serverCertificateValidationCallback = new RemoteCertificateValidationCallback (CheckValidationResult);} HttpWebRequest request = (HttpWebRequest) WebRequest. create (posturl); request. method = "POST"; request. contentType = "application/x-www-form-urlencoded"; // convert the json string to a byte array byte [] bytes = System. text. encoding. UTF8.GetBytes (jsonstr); // you can specify the ContentLength of the request. contentLength = bytes. length; // send the request to obtain the Stream stream of the request; try {// obtain the Stream object stream = request for writing the request data. getRequestStream ();} catch (Exception ex) {stream = null; Console. writeLine (ex. message);} // write data to the stream. write (bytes, 0, bytes. length); stream. close (); HttpWebResponse response; try {// get response stream response = (HttpWebResponse) request. getResponse ();} catch (WebException ex) {response = ex. response as HttpWebResponse;} Stream s = response. getResponseStream (); StreamReader sr = new StreamReader (s, Encoding. UTF8); string strVal = sr. readToEnd (). trim (); sr. close (); s. close (); return strVal;} public static bool CheckValidationResult (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) {return true ;}

 

Configure byte points for the wild dog cloud Application

 

 

Return after successful post

 

For the first time, I wrote only one record and hoped to help people in need.

 

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.