Browse files

VB template polishing

  • Loading branch information...
1 parent d4e3055 commit 0e964abf55f15aa3873c74cac90536d2d37d7fac @kuba-kubula kuba-kubula committed Jun 12, 2013
Showing with 16 additions and 17 deletions.
  1. +16 −17 vb.html
View
33 vb.html
@@ -1,30 +1,29 @@
<section name="vb" class="vb">
<p class="ioDesc">Request</p>
- <pre class="incoming"><code class="language-vb">
-Dim request = TryCast(System.Net.WebRequest.Create("<%= @apiUrl %><%= @url %>"), System.Net.HttpWebRequest)
+ <pre class="incoming"><code class="language-vb">Dim request = TryCast(System.Net.WebRequest.Create("<%= @apiUrl %><%= @url %>"), 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 %>)
+<% 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': %>
+<% if @body: %>
+<% if @method.toUpperCase() is 'POST' or @method.toUpperCase() is 'PUT' or @method.toUpperCase() is 'DELETE': %>
Using writer = New System.IO.StreamWriter(request.GetRequestStream())
- Dim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes("<%= @body.replace(/"/g, "'") %>")
- request.ContentLength = byteArray.Length
- writer.Write(byteArray)
- writer.Close()
+ Dim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes("<%= @helpers.escape(@body).slice(1, -1).replace(/"/g, '""') %>")
+ request.ContentLength = byteArray.Length
+ writer.Write(byteArray)
+ writer.Close()
End Using
- <% end %>
- <% else: %>
- request.ContentLength = 0
+<% end %>
+<% else: %>
+request.ContentLength = 0
<% end %>
Dim responseContent As String
Using response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
- Using reader = New System.IO.StreamReader(response.GetResponseStream())
- responseContent = reader.ReadToEnd()
- End Using
-End Using
-</code></pre></section>
+ Using reader = New System.IO.StreamReader(response.GetResponseStream())
+ responseContent = reader.ReadToEnd()
+ End Using
+End Using</code></pre></section>

0 comments on commit 0e964ab

Please sign in to comment.