Skip to content
Browse files

Add csharp template, wip

  • Loading branch information...
1 parent fc89f70 commit 548668cdb5bd732b8a04cc88f711536373c9ec00 @kfrancis kfrancis committed May 27, 2013
Showing with 25 additions and 0 deletions.
  1. +25 −0 csharp.html
View
25 csharp.html
@@ -0,0 +1,25 @@
+<section name="csharp" class="csharp">
+ <p class="ioDesc">Request</p>
+ <pre class="incoming">
+ <code class="language-csharp">
+ using System.Net;
+ var request = WebRequest.Create("<%= @apiUrl %><%= @url %>") as HttpWebRequest;
+ request.Method = "<%= @method.toUpperCase() %>";
+ request.ContentType = "<%= @contentType %>";
+ <% if @method.toUpperCase() is 'POST' or @method.toUpperCase() is 'PUT' @method.toUpperCase() is 'DELETE' and @helpers.isNotEmpty(@body) %>
+ using (var writer = new StreamWriter(request.GetRequestStream())) {
+ byte[] byteArray = Encoding.UTF8.GetBytes(<%= @helpers.escape @body %>);
+ request.ContentLength = byteArray.Length;
+ writer.Write(byteArray);
+ writer.Close();
+ }
+ <% end %>
+ string responseContent;
+ using (var response = request.GetResponse() as HttpWebResponse) {
+ using (var reader = new StreamReader(response.GetResponseStream())) {
+ responseContent = reader.ReadAllText();
+ }
+ }
+ </code>
+ </pre>
+</section>

0 comments on commit 548668c

Please sign in to comment.
Something went wrong with that request. Please try again.