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
34
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
  • 451
  • 1
  • 4
  • 9
31
votes
2 answers

RestSharp get full URL of a request

Is there a way to get the full url of a RestSharp request including its resource and querystring parameters? I.E for this request: RestClient client = new RestClient("http://www.some_domain.com"); RestRequest request = new…
Jaqen H'ghar
  • 13,728
  • 6
  • 42
  • 50
31
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
  • 1,970
  • 2
  • 24
  • 44
29
votes
5 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
  • 291
  • 1
  • 3
  • 3
27
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
  • 998
  • 1
  • 11
  • 27
26
votes
1 answer

Should RestClient be singleton or new for every request

ASP.Net HttpClient is disposable, and a lot of articles say you should use the singleton pattern to use it because of the performance. But when I see the RestClient it can't be disposed, and in the Recommended-Usage page the sample will new the…
MichaelMao
  • 1,531
  • 1
  • 16
  • 40
26
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
  • 891
  • 1
  • 7
  • 18
26
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
  • 23,877
  • 23
  • 111
  • 181
23
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
  • 9,586
  • 15
  • 93
  • 162
23
votes
3 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
  • 780
  • 1
  • 5
  • 22
23
votes
1 answer

How to access the HTTP request body using RestSharp?

I'm building a RESTful API client in 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 was stuck on was the automatic deserialization…
Epoc
  • 6,343
  • 8
  • 56
  • 63
22
votes
3 answers

Https POST/GET not working on Mono

I want to execute a HttpPost on a Raspberry using Mono + Restsharp. The Httpie call that i try to reproduce in code looks something like this: http POST https://XXXXX.azurewebsites.net/api/report key=value This is the C# code: RestClient nodeRed =…
quadroid
  • 7,621
  • 5
  • 41
  • 71
22
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,270
  • 12
  • 46
  • 71
22
votes
3 answers

RestSharp deserialize JSON content(represent an object contains an byte array) error

The Client side receives a formal JSON content "{\"Id\":[1,2,3],\"Size\":56}", but get an error in deserialization the byte array. 1 Error occurs in the statement below IRestResponse response = client.Execute(request); 2 Error message is…
Yan Zhengshan
  • 221
  • 1
  • 2
  • 4
21
votes
2 answers

Add a GET parameter to a POST request with RestSharp

I want to make a POST request to a URL like this: http://localhost/resource?auth_token=1234 And I want to send JSON in the body. My code looks something like this: var client = new RestClient("http://localhost"); var request = new…
leninyee
  • 316
  • 1
  • 2
  • 7