Permalink
Browse files

Merge pull request #6 from kfrancis/master

Add csharp template
  • Loading branch information...
2 parents fc89f70 + bf4f00a commit a00fc045cd3d378f73e0967403d74d280bc73486 @kuba-kubula kuba-kubula committed May 30, 2013
Showing with 30 additions and 0 deletions.
  1. +30 −0 csharp.html
View
@@ -0,0 +1,30 @@
+<section name="csharp" class="csharp">
+ <p class="ioDesc">Request</p>
+ <pre class="incoming"><code class="language-csharp">
+var request = System.Net.WebRequest.Create("<%= @apiUrl %><%= @url %>") as System.Net.HttpWebRequest;
+request.Method = "<%= @method.toUpperCase() %>";
+<% if @contentType: %>
+request.ContentType = "<%= @contentType %>";
+<% end %>
+<% if @headers: %>
+<% for header, value of @headers: %>request.Headers.Add(<%= @helpers.escape header %>, <%= @helpers.escape value %>);
+<% end %><% end %>
+<% if @helpers.isNotEmpty @body: %>
+ <% if @method.toUpperCase() is 'POST' or @method.toUpperCase() is 'PUT' or @method.toUpperCase() is 'DELETE': %>
+using (var writer = new System.IO.StreamWriter(request.GetRequestStream())) {
+ byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(<%= @helpers.escape @body %>);
+ request.ContentLength = byteArray.Length;
+ writer.Write(byteArray);
+ writer.Close();
+ }
+ <% end %>
+ <% else: %>
+ request.ContentLength = 0;
+<% end %>
+string responseContent;
+using (var response = request.GetResponse() as System.Net.HttpWebResponse) {
+ using (var reader = new System.IO.StreamReader(response.GetResponseStream())) {
+ responseContent = reader.ReadToEnd();
+ }
+}
+</code></pre></section>

0 comments on commit a00fc04

Please sign in to comment.