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.