0

Is there any way in REST Sharp version 111.3 to modify the Content-Type value inside the form data? Below is an example outgoing call I captured with Fiddler. As you can see, the content is JSON (AttributeFormat), but when I add that parameter, it's automatically adding text/plain

var request new RestRequest(options)
....
...
...
request.AddParameter("Arequest","{\"attributeFormat\":\"pdf\"}";
POST https://someurl.com/run HTTP/1.1

Authorization: Bearer adfafd....
User-Agent: RestSharp/111.3.0.0
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml 
Host: someurl.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary="215c45a3-b9aa-40f1-9eb5-8ceefb192370"
Content-Length: 204 

--215c45a3-b9aa-40f1-9eb5-8ceefb192370

Content-Disposition: form-data; name=ARequest
Content-Type: text/plain; charset=utf-8  <---- says text/plain instead of json!

{"attributeFormat":"pdf"}  <---- added as text!

--215c45a3-b9aa-40f1-9eb5-8ceefb192370--

Thanks for any help

Tried to add a JSON item to the body/form, but the Content-Type inside the boundary keeps listing it as text/plain instead of application/json

1 Answer 1

0

The Parameter base class has ContentType property. You can replace AddParameter call with:

var parameter = new GetOrPostParameter("Arequest","{\"attributeFormat\":\"pdf\"}");
parameter.ContentType = "application/json";
request.AddParameter(parameter);

Then, it should work.

Sign up to request clarification or add additional context in comments.

4 Comments

'Parameter.ContentType' can only be assigned in an object initializer, or on 'this' or 'base' in an instance constructor or an 'init' accessor
Right, I it seems like a bug. I will try fixing it.
It should work with v111.4.1
Just tested this and It works. Thank you..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.