From 3fd5bbc9d42a57c5e4834fdcb1b2ff8cd6d59deb Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Fri, 16 Jun 2023 19:19:15 -0400 Subject: [PATCH] fix: Support Restsharp 107+ (#179) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After version 107, restsharp completely changed their API. This PR fixes the code generator to support the new API. - also add the escaping function from https://github.com/Kong/httpsnippet/pull/289 - I think there are probably still escaping bugs here, but it seems to be working Well Enoughâ„¢ --- src/targets/csharp/restsharp/client.ts | 70 ++++++++++++++++--- .../fixtures/application-form-encoded.cs | 16 +++-- .../restsharp/fixtures/application-json.cs | 15 ++-- .../csharp/restsharp/fixtures/cookies.cs | 16 +++-- src/targets/csharp/restsharp/fixtures/full.cs | 19 +++-- .../csharp/restsharp/fixtures/headers.cs | 12 +++- .../restsharp/fixtures/http-insecure.cs | 12 +++- .../restsharp/fixtures/jsonObj-multiline.cs | 15 ++-- .../restsharp/fixtures/jsonObj-null-value.cs | 15 ++-- .../restsharp/fixtures/multipart-data.cs | 18 +++-- .../restsharp/fixtures/multipart-file.cs | 17 +++-- .../fixtures/multipart-form-data-no-params.cs | 14 ++-- .../restsharp/fixtures/multipart-form-data.cs | 17 +++-- .../csharp/restsharp/fixtures/nested.cs | 12 +++- .../restsharp/fixtures/postdata-malformed.cs | 13 ++-- .../restsharp/fixtures/query-encoded.cs | 12 +++- .../csharp/restsharp/fixtures/query.cs | 12 +++- .../csharp/restsharp/fixtures/short.cs | 12 +++- .../csharp/restsharp/fixtures/text-plain.cs | 15 ++-- 19 files changed, 243 insertions(+), 89 deletions(-) diff --git a/src/targets/csharp/restsharp/client.ts b/src/targets/csharp/restsharp/client.ts index 796e30016..20fa85cf3 100644 --- a/src/targets/csharp/restsharp/client.ts +++ b/src/targets/csharp/restsharp/client.ts @@ -2,7 +2,10 @@ import type { Client } from '../../targets'; import { CodeBuilder } from '../../../helpers/code-builder'; import { escapeForDoubleQuotes } from '../../../helpers/escape'; -import { getHeader } from '../../../helpers/headers'; + +function title(s: string): string { + return s[0].toUpperCase() + s.slice(1).toLowerCase(); +} export const restsharp: Client = { info: { @@ -11,7 +14,7 @@ export const restsharp: Client = { link: 'http://restsharp.org/', description: 'Simple REST and HTTP API Client for .NET', }, - convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }) => { + convert: ({ method, fullUrl, headersObj, cookies, postData, uriObj }) => { const { push, join } = new CodeBuilder(); const isSupportedMethod = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'].includes( method.toUpperCase() @@ -21,26 +24,71 @@ export const restsharp: Client = { return 'Method not supported'; } - push(`var client = new RestClient("${fullUrl}");`); - push(`var request = new RestRequest(Method.${method.toUpperCase()});`); + push('using RestSharp;\n\n'); + push(`var options = new RestClientOptions("${fullUrl}");`); + push('var client = new RestClient(options);'); - // Add headers, including the cookies + // The first argument is the sub-path to the base URL, given as the + // constructor to RestClient; for our purposes we're just giving the entire + // URL as the base path so it can be an empty string + push('var request = new RestRequest("");'); + + // If we have multipart form data, set this value. Setting the content-type header manually and then trying to add a mutlipart file parameter + const isMultipart = postData.mimeType && postData.mimeType === 'multipart/form-data'; + if (isMultipart) { + push('request.AlwaysMultipartFormData = true;'); + } + // Add headers, including the cookies Object.keys(headersObj).forEach(key => { + // if we have post data, restsharp really wants to set the contentType + // itself; do not add a content-type header or you end up with failures + // which manifest as unhandled exceptions. + if (postData.mimeType && key.toLowerCase() === 'content-type') { + if (isMultipart && postData.boundary) { + push(`request.FormBoundary = "${postData.boundary}";`); + } + return; + } push(`request.AddHeader("${key}", "${escapeForDoubleQuotes(headersObj[key])}");`); }); cookies.forEach(({ name, value }) => { - push(`request.AddCookie("${name}", "${value}");`); + push(`request.AddCookie("${name}", "${escapeForDoubleQuotes(value)}", "${uriObj.pathname}", "${uriObj.host}");`); }); - if (postData.text) { - const header = getHeader(allHeaders, 'content-type'); - const text = JSON.stringify(postData.text); - push(`request.AddParameter("${header}", ${text}, ParameterType.RequestBody);`); + switch (postData.mimeType) { + case 'multipart/form-data': + if (!postData.params) break; + postData.params.forEach(param => { + if (param.fileName) { + push(`request.AddFile("${param.name}", "${param.fileName}");`); + } else { + push(`request.AddParameter("${param.name}", "${param.value}");`); + } + }); + break; + case 'application/x-www-form-urlencoded': + if (!postData.params) break; + postData.params.forEach(param => { + push(`request.AddParameter("${param.name}", "${param.value}");`); + }); + break; + case 'application/json': { + if (!postData.text) break; + const text = JSON.stringify(postData.text); + push(`request.AddJsonBody(${text}, false);`); + break; + } + default: + if (!postData.text) break; + push(`request.AddStringBody("${postData.text}", "${postData.mimeType}");`); } - push('IRestResponse response = client.Execute(request);'); + push(`var response = await client.${title(method)}Async(request);\n`); + + push('Console.WriteLine("{0}", response.Content);'); + return join(); }, }; diff --git a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs index 05f6dddcb..c1acb2e73 100644 --- a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs @@ -1,5 +1,11 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "application/x-www-form-urlencoded"); -request.AddParameter("application/x-www-form-urlencoded", "foo=bar&hello=world", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AddParameter("foo", "bar"); +request.AddParameter("hello", "world"); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/application-json.cs b/src/targets/csharp/restsharp/fixtures/application-json.cs index 49d90e16c..589036384 100644 --- a/src/targets/csharp/restsharp/fixtures/application-json.cs +++ b/src/targets/csharp/restsharp/fixtures/application-json.cs @@ -1,5 +1,10 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "application/json"); -request.AddParameter("application/json", "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":[]}],\"boolean\":false}", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AddJsonBody("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":[]}],\"boolean\":false}", false); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/cookies.cs b/src/targets/csharp/restsharp/fixtures/cookies.cs index d2a59ac10..1bedc6df1 100644 --- a/src/targets/csharp/restsharp/fixtures/cookies.cs +++ b/src/targets/csharp/restsharp/fixtures/cookies.cs @@ -1,5 +1,11 @@ -var client = new RestClient("https://httpbin.org/cookies"); -var request = new RestRequest(Method.GET); -request.AddCookie("foo", "bar"); -request.AddCookie("bar", "baz"); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/cookies"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AddCookie("foo", "bar", "/cookies", "httpbin.org"); +request.AddCookie("bar", "baz", "/cookies", "httpbin.org"); +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/full.cs b/src/targets/csharp/restsharp/fixtures/full.cs index d18090a79..aa3fd11d7 100644 --- a/src/targets/csharp/restsharp/fixtures/full.cs +++ b/src/targets/csharp/restsharp/fixtures/full.cs @@ -1,8 +1,13 @@ -var client = new RestClient("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); -var request = new RestRequest(Method.POST); +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); +var client = new RestClient(options); +var request = new RestRequest(""); request.AddHeader("accept", "application/json"); -request.AddHeader("content-type", "application/x-www-form-urlencoded"); -request.AddCookie("foo", "bar"); -request.AddCookie("bar", "baz"); -request.AddParameter("application/x-www-form-urlencoded", "foo=bar", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +request.AddCookie("foo", "bar", "/anything", "httpbin.org"); +request.AddCookie("bar", "baz", "/anything", "httpbin.org"); +request.AddParameter("foo", "bar"); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/headers.cs b/src/targets/csharp/restsharp/fixtures/headers.cs index 838765d10..6cdb2c4be 100644 --- a/src/targets/csharp/restsharp/fixtures/headers.cs +++ b/src/targets/csharp/restsharp/fixtures/headers.cs @@ -1,7 +1,13 @@ -var client = new RestClient("https://httpbin.org/headers"); -var request = new RestRequest(Method.GET); +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/headers"); +var client = new RestClient(options); +var request = new RestRequest(""); request.AddHeader("accept", "application/json"); request.AddHeader("x-foo", "Bar"); request.AddHeader("x-bar", "Foo"); request.AddHeader("quoted-value", "\"quoted\" 'string'"); -IRestResponse response = client.Execute(request); \ No newline at end of file +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/http-insecure.cs b/src/targets/csharp/restsharp/fixtures/http-insecure.cs index 7fd60f467..79986efb8 100644 --- a/src/targets/csharp/restsharp/fixtures/http-insecure.cs +++ b/src/targets/csharp/restsharp/fixtures/http-insecure.cs @@ -1,3 +1,9 @@ -var client = new RestClient("http://httpbin.org/anything"); -var request = new RestRequest(Method.GET); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("http://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs index e0ee8ed20..2bd85bd7a 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs @@ -1,5 +1,10 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "application/json"); -request.AddParameter("application/json", "{\n \"foo\": \"bar\"\n}", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AddJsonBody("{\n \"foo\": \"bar\"\n}", false); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs index 21685e0c5..a9a5ca673 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs @@ -1,5 +1,10 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "application/json"); -request.AddParameter("application/json", "{\"foo\":null}", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AddJsonBody("{\"foo\":null}", false); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-data.cs index f0e00ceb9..b256b6997 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-data.cs @@ -1,5 +1,13 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); -request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AlwaysMultipartFormData = true; +request.FormBoundary = "---011000010111000001101001"; +request.AddFile("foo", "src/fixtures/files/hello.txt"); +request.AddParameter("bar", "Bonjour le monde"); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-file.cs b/src/targets/csharp/restsharp/fixtures/multipart-file.cs index 03cd703e1..d1fda9b99 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-file.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-file.cs @@ -1,5 +1,12 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); -request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AlwaysMultipartFormData = true; +request.FormBoundary = "---011000010111000001101001"; +request.AddFile("foo", "src/fixtures/files/hello.txt"); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs index 79f99ba17..f52b66da6 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs @@ -1,4 +1,10 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("Content-Type", "multipart/form-data"); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AlwaysMultipartFormData = true; +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs index 0d8e48f7d..2456020a1 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs @@ -1,5 +1,12 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("Content-Type", "multipart/form-data; boundary=---011000010111000001101001"); -request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AlwaysMultipartFormData = true; +request.FormBoundary = "---011000010111000001101001"; +request.AddParameter("foo", "bar"); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/nested.cs b/src/targets/csharp/restsharp/fixtures/nested.cs index 345a3c7a5..57b8ffb28 100644 --- a/src/targets/csharp/restsharp/fixtures/nested.cs +++ b/src/targets/csharp/restsharp/fixtures/nested.cs @@ -1,3 +1,9 @@ -var client = new RestClient("https://httpbin.org/anything?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"); -var request = new RestRequest(Method.GET); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs b/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs index e7a496e4d..147e990fa 100644 --- a/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs +++ b/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs @@ -1,4 +1,9 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "application/json"); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/query-encoded.cs b/src/targets/csharp/restsharp/fixtures/query-encoded.cs index c998ebb76..f60e554dc 100644 --- a/src/targets/csharp/restsharp/fixtures/query-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/query-encoded.cs @@ -1,3 +1,9 @@ -var client = new RestClient("https://httpbin.org/anything?startTime=2019-06-13T19%3A08%3A25.455Z&endTime=2015-09-15T14%3A00%3A12-04%3A00"); -var request = new RestRequest(Method.GET); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything?startTime=2019-06-13T19%3A08%3A25.455Z&endTime=2015-09-15T14%3A00%3A12-04%3A00"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/query.cs b/src/targets/csharp/restsharp/fixtures/query.cs index 0d8135f6e..bca7ca7b7 100644 --- a/src/targets/csharp/restsharp/fixtures/query.cs +++ b/src/targets/csharp/restsharp/fixtures/query.cs @@ -1,3 +1,9 @@ -var client = new RestClient("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); -var request = new RestRequest(Method.GET); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/short.cs b/src/targets/csharp/restsharp/fixtures/short.cs index a62cf8a80..76ad84cec 100644 --- a/src/targets/csharp/restsharp/fixtures/short.cs +++ b/src/targets/csharp/restsharp/fixtures/short.cs @@ -1,3 +1,9 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.GET); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/text-plain.cs b/src/targets/csharp/restsharp/fixtures/text-plain.cs index c434206c7..20d61e5b7 100644 --- a/src/targets/csharp/restsharp/fixtures/text-plain.cs +++ b/src/targets/csharp/restsharp/fixtures/text-plain.cs @@ -1,5 +1,10 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "text/plain"); -request.AddParameter("text/plain", "Hello World", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +using RestSharp; + + +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AddStringBody("Hello World", "text/plain"); +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file