Oauth request using RestSharp

259 views
Skip to first unread message

Ilya Epshteyn

unread,
Apr 2, 2021, 9:14:46 AM4/2/21
to RestSharp

I am trying to send oauth request to receive a token and no matter what I do I get an error that nonce was already used. So I decided to send that same request using Fiddler and everything worked flawlessly. The only issue I see is with the request body. I have to send grant_type=client_credentials in the body and it must be of application/x-www-form-urlencoded type. not Json nor XML. RestSharp describes adding JsonBody and XMLbody but both of those would set incorrect content type to the request. Plus it says this:

The name of the parameter will be used as the Content-Type header for the request.

In my code I am trying to add the body the following way:

req.AddParameter("grant_type", "client_credentials", ParameterType.RequestBody)

Is that the correct way to add request body? I am also open to all suggestions to what else might be causing that error

Thank you

Alexey Zimarev

unread,
May 7, 2021, 5:35:08 PM5/7/21
to RestSharp
Reply all
Reply to author
Forward
0 new messages