jgiacomini / Tiny.RestClient

Simpliest Fluent REST client for .NET
MIT License
210 stars 30 forks source link

Support `-F` / `--form` in MultiPartFromDataRequest #120

Open dariusz-wozniak opened 2 years ago

dariusz-wozniak commented 2 years ago

I'd like to translate the following cURL to the Tiny.RestClient request:

curl -v -u yourapikey:X -F "attachments[]=@/path/to/attachment1.ext" -F "attachments[]=@/path/to/attachment2.ext" -F "email=example@example.com" -F "subject=Ticket Title" -F "description=this is a sample ticket" -X POST 'https://domain.freshdesk.com/api/v2/tickets'

When I use the client to post the request:

var rs = await client.PostRequest("tickets")
                     .AsMultiPartFromDataRequest()
                     .AddString("a@a.com", "email")
                     .ExecuteAsStringAsync(CancellationToken.None);

...And I have a cURL listener (client.Settings.Listeners.AddCurl()), the translated cURL is (some data stripped off):

curl -X POST [...] -d "--1c3acb07-77bd-494d-bc56-21290dcd5088
Content-Type: text/plain
Content-Disposition: form-data; name=email

a@a.com
[...]

The "email" param is passed with the -d flag; how can I make the param passed by -F flag?

dariusz-wozniak commented 2 years ago

The actual problem is Freshdesk API and its requirement to have parameters wrapped in quotation marks.

See the thread: https://github.com/restsharp/RestSharp/issues/1744.