Kong / apiembed

Embeddable API code snippets for your website, blog or API documentation
https://apiembed.com
MIT License
410 stars 52 forks source link

Pure C# #26

Closed Clint66 closed 5 years ago

Clint66 commented 7 years ago

C# without RestClient

var request = WebRequest.CreateHttp("https://api.whispir.com/messages?apikey=<REPLACE_ME>");
request.Method = "POST";
request.ContentType = "application/vnd.whispir.message-v1+json";
request.Accept = "application/vnd.whispir.message-v1+json";
request.Headers.Add("authorization", "<REPLACE_ME>");

var bytes = Encoding.UTF8.GetBytes("{\"to\":\"<REPLACE_ME>\",\"subject\":\"<REPLACE_ME>\",\"body\":\"<REPLACE_ME>\"}");

request.ContentLength = bytes.Length;

using (var stream = request.GetRequestStream()) {
    stream.Write(bytes, 0, bytes.Length);
    try {
        using (var response = request.GetResponse()) {
            var result = (new StreamReader(response.GetResponseStream())).ReadToEnd();
        }
    }
    catch (WebException wex) {
        using (var response = wex.Response) {
            var error = (new StreamReader(response.GetResponseStream())).ReadToEnd();
        }
    }
}
nijikokun commented 5 years ago

Cleaning up old issues, so closing this out, this should be raised on HTTPSnippet if it is still an issue. Thank you!