This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathvb.html
41 lines (37 loc) · 1.99 KB
/
vb.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<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)
request.Method = "<%= @method.toUpperCase() %>"
<% if @headers and @helpers.isNotEmpty @headers: %>
<% for header, value of @headers: %>
<% header = header.toLowerCase() %>
<% if header in ['accept', 'connection', 'date', 'expect', 'host', 'range', 'referer']: %>request.<%- header.charAt(0).toUpperCase() %><%- header.substring(1).toLowerCase() %> = <%= @helpers.escape value %>
<% else if header is 'content-length': %>request.ContentLength = <%= @helpers.escape value %>
<% else if header is 'content-type': %>request.ContentType = <%= @helpers.escape value %>
<% else if header is 'if-modified-since': %>request.IfModifiedSince = <%= @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 'proxy-connection': %>request.ProxyConnection = <%= @helpers.escape value %>
<% else: %>
request.Headers.Add(<%= @helpers.escape header %>, <%= @helpers.escape value %>)
<% end %>
<% end %>
<% end %>
<% 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("<%= @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 %>
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>