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

2486 questions
43
votes
7 answers

RestSharp HttpBasicAuthentication - example

I have a WPF client using RestSharp and WEB API Service. I try to use HttpBasicAuthenticator as follows: RestRequest login = new RestRequest("/api/users/login", Method.POST); var authenticator = new…
RomaS
  • 431
  • 1
  • 4
  • 3
39
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
  • 832
  • 1
  • 9
  • 10
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
  • 66,056
  • 18
  • 147
  • 180
35
votes
6 answers

How should I implement ExecuteAsync with RestSharp on Windows Phone 7?

I'm attempting to use the documentation on the RestSharp GitHub wiki to implement calls to my REST API service but I'm having an issue with the ExecuteAsync method in particular. Currently my code looks like this for the API class: public class…
joshcollie
  • 471
  • 1
  • 4
  • 9
34
votes
3 answers

RestSharp Timeout not working

I have a restsharp client and request set up like this: var request = new RestRequest(); request.Method = Method.POST; request.AddParameter("application/json", jsonBody, ParameterType.RequestBody); request.OnBeforeDeserialization = resp => {…
Miljan Vulovic
  • 1,586
  • 3
  • 20
  • 48
32
votes
2 answers

How to use OAuth2 in RestSharp

After a couple of days sorting out OAuth2 at the server-end (Spring java) I started working on the client written in C#. I am using RestSharp to call my web API but I am having real difficulty with the OAuth2. There is hardly any documentation and…
Dimitris
  • 2,030
  • 3
  • 27
  • 45
29
votes
2 answers

Why is my async/await with CancellationTokenSource leaking memory?

I have a .NET (C#) application that makes extensive use of async/await. I feel like I've got my head around async/await, but I'm trying to use a library (RestSharp) that has an older (or perhaps I should just say different) programming model that…
Gary McGill
  • 26,400
  • 25
  • 118
  • 202
28
votes
5 answers

RestSharp Post a JSON Object

I am trying to post the following JSON with RestSharp: {"UserName":"UAT1206252627", "SecurityQuestion":{ "Id":"Q03", "Answer":"Business", "Hint":"The answer is Business" }, } I think that I am close, but I seem to be struggling with the…
JamesWillett
  • 980
  • 2
  • 8
  • 20
27
votes
2 answers

Sending HTTP POST Multipart/form-data field using RestSharp

I'm having issues using RestSharp for a REST API I need to use for a project I'm working on. The request I need to issue is in three parts: A header API key, a file to upload, and a bunch of data in JSON format. The API requires that the data…
JNYRanger
  • 6,829
  • 12
  • 53
  • 81
26
votes
4 answers

How to use RestSharp.NetCore in asp.net core

I have gone through the http://restsharp.org/ code which work greats. Below is the code of RestSharp with out asp.net core . public GenericResponseObject GetGeneric(string operation, params KeyValuePair[] nameValues) where T :…
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
26
votes
2 answers

Dynamically deserializing to a property in RestSharp

I am playing with the Harvest API and I'm trying to automatically map the entities as easy as possible, unfortunately when I do a request like GET /projects it generates a result like so: [{ project: { name: "Test" } }, { …
Chris
  • 1,068
  • 2
  • 14
  • 30
26
votes
4 answers

RestSharp - Authorization Header not coming across to WCF REST service

I am trying to call a locally hosted WCF REST service over HTTPS with basic auth. This works and the Authorization header comes thru just fine and all is happy: ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertficate; var…
Chris Hawkins
  • 808
  • 1
  • 7
  • 22
26
votes
1 answer

How to access the HTTP request body using RestSharp?

I'm building a RESTful API client using C# .NET 3.5. I first started building it with the good old HttpWebClient (and HttpWebResponse), I could do whatever I wanted with. I were happy. The only thing I stumbled upon was the automatic deserialization…
Epoc
  • 7,208
  • 8
  • 62
  • 66
24
votes
3 answers

Add certificate on request with RestSharp

I'm trying to communicate with a server. This server send me a certificate and a private key in order to execute my request successfully. To test the server, I use Postman. So I fill the certificate setting in postman, and my request works fine Now…
dpfauwadel
  • 3,866
  • 3
  • 23
  • 40
24
votes
3 answers

API is returning error when using RESTSHARP

When use RestSharp to call an API I get this error: The underlying connection was closed: An unexpected error occurred on a send. I've verified that my client ID, secret, username, and password are correct. I'm able to do this without issues in…
Funkel
  • 133
  • 1
  • 6
  • 21