-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenerateCode.tt
53 lines (53 loc) · 1.34 KB
/
GenerateCode.tt
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
42
43
44
45
46
47
48
49
50
51
52
53
<#@ template language="C#" #>
<#@ import namespace="Fiddler"#>
<#@ parameter type="System.String" name="uri" #>
<#@ parameter type="System.String" name="httpmethod" #>
<#@ parameter type="System.Collections.Generic.Dictionary<string,string>" name="headers" #>
<#@ parameter type="System.Collections.Generic.Dictionary<string,string>" name="bodies" #>
var uriBuilder = new UriBuilder("<# Write(uri); #>");
var httpClient = new HttpClient();
<#
if(httpmethod.ToUpper()=="GET")
{
#>
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uriBuilder.ToString());
<#
}
#>
<#
if(httpmethod.ToUpper()=="POST")
{
#>
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, uriBuilder.ToString());
<#
}
#>
<#
foreach (var item in headers)
{
#>
httpRequestMessage.Headers.Add("<# Write(item.Key.ToString()); #>","<# Write(item.Value.ToString()); #>");
<#
}
#>
<#
if(bodies.Count > 0)
{
#>
var values = new Dictionary<string, string>();
<#
foreach (var item in bodies)
{
#>
values.Add("<# Write(item.Key.ToString()); #>","<# Write(item.Value.ToString()); #>");
<#
}
#>
var content = new FormUrlEncodedContent(values);
httpRequestMessage.Content = content;
<#
}
#>
var httpResponseMessage = httpClient.SendAsync(httpRequestMessage).Result;
var httpContent = httpResponseMessage.Content;
string result = httpResponseMessage.Content.ReadAsStringAsync().Result;