Questions tagged [restsharp]

RestSharp is a simple to use REST client library for .NET

RestSharp takes the pain out of calling REST services from .NET. This library takes care of the quirks in .NET's HTTP classes, handles deserialization cleanly, simplifies making asynchronous calls, and just makes it really easy to implement calls to REST services from inside your application.

RestSharp comes with a built-in JSON serializer. The default serializer has been compatible with the Json.NET project but this compatibility has been given up since release 100.3.

Installation Installing RestSharp can most easily be done using its NuGet package:

Install-Package RestSharp

Resources

2061 questions
152
votes
7 answers

RestSharp JSON Parameter Posting

I am trying to make a very basic REST call to my MVC 3 API and the parameters I pass in are not binding to the action method. Client var request = new RestRequest(Method.POST); request.Resource = "Api/Score"; request.RequestFormat =…
Wesley Tansey
  • 4,345
  • 9
  • 38
  • 64
107
votes
2 answers

How to use RestSharp with async/await

I'm struggling to find a modern example of some asynchronous C# code that uses RestSharp with async and await. I know there's been a recent update by Haack but I don't know how to use the new methods. Also, how can I provide a cancellation token so…
Pure.Krome
  • 78,923
  • 102
  • 356
  • 586
106
votes
2 answers

How to add text to request body in RestSharp

I'm trying to use RestSharp to consume a web service. So far everything's gone very well (cheers to John Sheehan and all contributors!) but I've run into a snag. Say I want to insert XML into the body of my RestRequest in its already serialized form…
Matt G.
  • 1,632
  • 2
  • 11
  • 16
101
votes
3 answers

RestSharp simple complete example

I've been trying to create a simple prototype web application that uses RestSharp to call Rest API. I've not been able to find one good example of it. Could anyone please share and direct me to right resource please? I've already looked at…
Nil Pun
  • 16,019
  • 34
  • 150
  • 277
78
votes
3 answers

RestSharp - Ignore SSL errors

Is there any whay that I can get RestSharp to ignore errors in SSL certificates? I have a test client, and the service I connect to does not yet have a valid cetificate. When I make a request now I get the error: The underlying connection was…
Michael Skarum
  • 2,020
  • 1
  • 14
  • 19
70
votes
8 answers

RestSharp print raw request and response headers

I'm using RestSharp to make calls to a webservice. All is well but I was wondering if it would be possible to print the raw request headers and body that is sent out and the raw response headers and the response body that comes back. This is my code…
Professor Chaos
  • 7,900
  • 7
  • 33
  • 52
70
votes
4 answers

Converting a JToken (or string) to a given Type

TL;DR Version I have a object of type JToken (but can also be a string) and I need to convert it into a Type contained in the type variable: Type type = typeof(DateTime); /* can be any other Type like string, ulong etc */ var obj =…
Uzair Sajid
  • 2,046
  • 2
  • 19
  • 28
59
votes
8 answers

How do I get an OAuth 2.0 authentication token in C#

I have these settings: Auth URL (which happens to be a "https://login.microsoftonline.com/...") if that helps. Access Token URL "https://service.endpoint.com/api/oauth2/token" ClientId "abc" Clientsecret "123" I then need to make a get call using…
Matt C
  • 846
  • 1
  • 9
  • 15
50
votes
2 answers

What is default timeout value of RestSharp RestClient?

Anybody aware of default timeout value of RestSharp RestClient ?
theGeekster
  • 5,421
  • 10
  • 31
  • 46
45
votes
4 answers

RestSharp post request - Body with x-www-form-urlencoded values

I am using postman and making an api post request where I am adding body with x-www-form-urlencoded key/values and it works fine in postman. The issue arrises when I try it from c# using RestSharp package. I have tried the following code below but…
nicedev80
  • 1,403
  • 1
  • 10
  • 17
45
votes
2 answers

Deserializing a json string with restsharp

I have a string that comes out of a database which is in Json format. I have tried to deserialize it with: RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer(); var x = deserial .Deserialize(myStringFromDB) But the…
Ian Vink
  • 60,720
  • 99
  • 311
  • 535
41
votes
5 answers

How to POST request using RestSharp

I m trying to POST the request using RestSharp client as follows I m passing the Auth Code to following function public void ExchangeCodeForToken(string code) { if (string.IsNullOrEmpty(code)) { OnAuthenticationFailed(); } …
Ashish
  • 743
  • 2
  • 8
  • 16
38
votes
5 answers

How to use restsharp to download file

I have a URL (URL for the live feed from client) which when I hit in browser returns the xml response . I have saved this in text file it`s size is 8 MB. now my problem is that I need to save this response in xml file on server`s drive. from there…
Learner
  • 1,018
  • 3
  • 12
  • 29
37
votes
1 answer

Are these the main differences between RestSharp and ServiceStack's Client Code?

I have been unable to make a definitive choice and was hoping that somebody (or a combination of a couple of people) could point out the differences between using RestSharp versus ServiceStack's client services (keeping in mind that I am already…
Justin Pihony
  • 62,016
  • 17
  • 131
  • 162
35
votes
5 answers

Set 'Content-Type' header using RestSharp

I'm building a client for an RSS reading service. I'm using the RestSharp library to interact with their API. The API states: When creating or updating a record you must set application/json;charset=utf-8 as the Content-Type header. This is what…
Shane Gowland
  • 762
  • 1
  • 8
  • 10
1
2 3
99 100