Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix C# examples for HttpWebRequest.Headers property #8

Merged
merged 1 commit into from

2 participants

@zzen
Owner

Almad says I should ping @kuba-kubula with this.

@zdne
Owner

As per @kuba-kubula green I am merging this PR.

@zdne zdne merged commit 20386e0 into from
@zdne zdne deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 23, 2013
  1. @zdne
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 2 deletions.
  1. +18 −2 csharp.html
View
20 csharp.html
@@ -6,8 +6,24 @@
request.ContentType = "<%= @contentType %>";
<% end %>
<% if @headers and @helpers.isNotEmpty @headers: %>
- <% for header, value of @headers: %>request.Headers.Add(<%= @helpers.escape header %>, <%= @helpers.escape value %>);
-<% end %><% end %>
+ <% for header, value of @headers: %>
+ <% header = header.toLowerCase() %>
+ <% if header is 'accept': %>request.Accept = "<%= @helpers.escape value %>";
+ <% else if header is 'connection': %>request.Connection = "<%= @helpers.escape value %>";
+ <% else if header is 'content-length': %>request.ContentLength = "<%= @helpers.escape value %>";
+ <% else if header is 'expect': %>request.Expect = "<%= @helpers.escape value %>";
+ <% else if header is 'date': %>request.Date = "<%= @helpers.escape value %>";
+ <% else if header is 'host': %>request.Host = "<%= @helpers.escape value %>";
+ <% else if header is 'if-modified-since': %>request.IfModifiedSince = "<%= @helpers.escape value %>";
+ <% else if header is 'range': %>request.AddRange = "<%= @helpers.escape value %>";
+ <% else if header is 'referer': %>request.Referer = "<%= @helpers.escape value %>";
+ <% else if header is 'transfer-encoding': %>request.TransferEncoding = "<%= @helpers.escape value %>";
+ <% else if header is 'user-agent': %>request.UserAgent = "<%= @helpers.escape value %>";
+ <% else if header is 'connection': %>request.Connection = "<%= @helpers.escape value %>";
+ <% else: %>request.Headers.Add(<%= @helpers.escape header %>, <%= @helpers.escape value %>);
+ <% end %>
+ <% end %>
+<% end %>
<% if @body?.length > 0: %>
<% if @method.toUpperCase() is 'POST' or @method.toUpperCase() is 'PUT' or @method.toUpperCase() is 'DELETE' or @body.length > 0: %>
using (var writer = new System.IO.StreamWriter(request.GetRequestStream())) {
Something went wrong with that request. Please try again.