Home > OS >  Flurl \ RestSharp: `\r\n` is added to each parameter of the Multipart request
Flurl \ RestSharp: `\r\n` is added to each parameter of the Multipart request

Time:02-14

I'm trying to write a call to the Freshdesk API using either Flurl or RestSharp library.

The API call I'm trying to write is Creating a Ticket: enter image description here

Update 2

I tried to use Tiny.RestClient which has cURL listener and it came with the following cURL generated:

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

[email protected]
[...]

Perhaps, Flurl and RestSharp uses the same way to proceed with parameters and thus, the \r\n in fields.

CodePudding user response:

It's the FreshDesk API issue. They want, for some reason, for multipart form-data parameter names to be enclosed in quotation marks. It's not a requirement per HTTP standards. RestSharp and Flurl use MultipartFormDataContent, and it adds uses parameter names as provided.

Following up on your issue, I added this property to RestRequest:

/// <summary>
/// When set to true, parameters in a multipart form data requests will be enclosed in
/// quotation marks. Default is false. Enable it if the remote endpoint requires parameters
/// to be in quotes (for example, FreshDesk API). 
/// </summary>
public bool MultipartFormQuoteParameters { get; set; }

It is available in RS 107.3.0.

You can also make it work by adding parameters like this:

request.AddParameter("\"status\"", ticket.Status);
  • Related