@@ -37,7 +37,7 @@ If you like this project, learn something or you are using it in your applicatio
3737
3838## ** How to use HttpClientToCurlGenerator** :
3939
40- ### Sample code for ** Post Method** (it will be written in the ** console** ):
40+ ### ** Post Method** sample code (it will be written in the ** console** ):
4141```
4242 string requestBody = @"{ ""name"" : ""amin"",""requestId"" : ""10001000"",""amount"":10000 }";
4343 string requestUri = "api/test";
@@ -61,7 +61,7 @@ If you like this project, learn something or you are using it in your applicatio
6161 // Call PostAsync => await client.PostAsync(requestUri, httpRequest.Content);
6262```
6363
64- ### Sample code ** Post Method** for FormUrlEncodedContent (it will be written in the ** console** ):
64+ ### ** Post Method** sample code for FormUrlEncodedContent (it will be written in the ** console** ):
6565```
6666 string requestBody = @"{ ""name"" : ""justin"",""requestId"" : 10001026,""amount"":26000 }";
6767 string requestUri = "api/test";
@@ -89,7 +89,7 @@ If you like this project, learn something or you are using it in your applicatio
8989 // Call PostAsync => await client.PostAsync(requestUri, httpRequest.Content);
9090```
9191
92- ### Sample code for ** Post Method** without set the requestUri (it will be written in the ** console** ):
92+ ### ** Post Method** sample code without set the requestUri (it will be written in the ** console** ):
9393```
9494 string requestBody = @"{ ""name"" : ""soozan"",""requestId"" : ""10001027"",""amount"":27000 }";
9595 var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "api/test");
@@ -111,7 +111,39 @@ If you like this project, learn something or you are using it in your applicatio
111111 // Call PostAsync => await client.PostAsync(httpRequestMessage.RequestUri?.ToString(), httpRequest.Content);
112112```
113113
114- ### Sample code for ** Post Method** (it will be written in the ** file** ):
114+ ### ** Post Method** sample code for xml (it will be written in the ** console** ):
115+
116+ ```
117+ public void GenerateCurl_For_PostMethod()
118+ {
119+ string requestBody = @"<?xml version = ""1.0"" encoding = ""UTF-8""?>
120+ <Order>
121+ <Id>12</Id>
122+ <name>Jason</name>
123+ <requestId>10001024</requestId>
124+ <amount>240000</amount>
125+ </Order>";
126+
127+ var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "api/test");
128+ httpRequestMessage.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");
129+ httpRequestMessage.Headers.Add("Authorization", Guid.NewGuid().ToString());
130+
131+ using var httpClient = new HttpClient();
132+ httpClient.BaseAddress = new Uri("http://localhost:1213");
133+
134+ httpClient.GenerateCurlInConsole(
135+ httpRequestMessage,
136+ config: config =>
137+ {
138+ config.TurnOn = true;
139+ config.NeedAddDefaultHeaders = true;
140+ config.EnableCodeBeautification = false;
141+ });
142+
143+ // Call PostAsync => await client.PostAsync(requestUri, httpRequest.Content);
144+ ```
145+
146+ ### ** Post Method** sample code (it will be written in the ** file** ):
115147
116148If the path variable is null or empty, then the file is created in the ** root project** .
117149
@@ -142,7 +174,7 @@ If the filename variable is null or empty, then the current date will be set for
142174 // Call PostAsync => await client.PostAsync(requestUri, httpRequest.Content);
143175```
144176
145- ### Sample code for ** Get Method** (it will be written in the ** console** ):
177+ ### ** Get Method** sample code (it will be written in the ** console** ):
146178```
147179 string requestUri = "api/test";
148180 var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);
@@ -165,7 +197,7 @@ If the filename variable is null or empty, then the current date will be set for
165197 // Call GetAsync => await client.GetAsync(requestUri);
166198```
167199
168- ### Sample code for ** Get Method** (it will be written in the ** file** ):
200+ ### ** Get Method** sample code (it will be written in the ** file** ):
169201
170202If the path variable is null or empty, then the file is created in the ** root project** .
171203
@@ -195,7 +227,7 @@ If the filename variable is null or empty, then the current date will be set for
195227 // Call GetAsync => await client.GetAsync(requestUri);
196228```
197229
198- ### Sample code for ** Put Method** (it will be written in the ** console** ):
230+ ### ** Put Method** sample code (it will be written in the ** console** ):
199231```
200232 string requestBody = @"{ ""name"" : ""jadi"",""requestId"" : ""10001003"",""amount"":30000 }";
201233 string requestUri = "api/test";
@@ -219,7 +251,7 @@ If the filename variable is null or empty, then the current date will be set for
219251 // Call PutAsync => await client.PutAsync(requestUri, httpRequest.Content);
220252```
221253
222- ### Sample code for ** Put Method** (it will be written in the ** file** ):
254+ ### ** Put Method** sample code (it will be written in the ** file** ):
223255
224256If the path variable is null or empty, then the file is created in the ** root project** .
225257
@@ -250,7 +282,7 @@ If the filename variable is null or empty, then the current date will be set for
250282 // Call PutAsync => await client.PutAsync(requestUri, httpRequest.Content);
251283```
252284
253- ### Sample code for ** Patch Method** (it will be written in the ** console** ):
285+ ### ** Patch Method** sample code (it will be written in the ** console** ):
254286```
255287 string requestBody = @"{ ""name"" : ""hamed"",""requestId"" : ""10001005"",""amount"":50000 }";
256288 string requestUri = "api/test";
@@ -274,7 +306,7 @@ If the filename variable is null or empty, then the current date will be set for
274306 // Call PatchAsync => await client.PatchAsync(requestUri, httpRequest.Content);
275307```
276308
277- ### Sample code for ** Patch Method** (it will be written in the ** file** ):
309+ ### ** Patch Method** sample code (it will be written in the ** file** ):
278310
279311If the path variable is null or empty, then the file is created in the ** root project** .
280312
@@ -305,7 +337,7 @@ If the filename variable is null or empty, then the current date will be set for
305337 // Call PatchAsync => await client.PatchAsync(requestUri, httpRequest.Content);
306338```
307339
308- ### Sample code for ** Delete Method** (it will be written in the ** console** ):
340+ ### ** Delete Method** sample code (it will be written in the ** console** ):
309341```
310342 int id = 12;
311343 string requestUri = $"api/test/{id}";
@@ -329,7 +361,7 @@ If the filename variable is null or empty, then the current date will be set for
329361 // Call DeleteAsync => await client.DeleteAsync(requestUri);
330362```
331363
332- ### Sample code for ** Delete Method** (it will be written in the ** file** ):
364+ ### ** Delete Method** sample code (it will be written in the ** file** ):
333365
334366If the path variable is null or empty, then the file is created in the ** root project** .
335367
@@ -360,4 +392,6 @@ If the filename variable is null or empty, then the current date will be set for
360392 // Call DeleteAsync => await client.DeleteAsync(requestUri);
361393```
362394
363- I Hope Enjoying this extension in your projects.
395+ ** You can see more samples in UnitTest files in Project.**
396+
397+ I hope enjoying this extension in your projects.
0 commit comments