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
24
votes
3 answers

Difference between RestSharp methods AddParameter and AddQueryParameter using HttpGET

I'm using RestSharp to call an external API. This works: var client = new RestClient(apiUrl); var request = new RestRequest(myurl, Method.GET); foreach (var param in parameters) { request.AddQueryParameter(param.Key, param.Value); } var…
Nic
  • 12,220
  • 20
  • 77
  • 105
23
votes
2 answers

RestSharp OAuth2 Bearer Authentication Failing With Access Denied

I have implemented my own custom IAuthenticator called OAuth2BearerAuthenticator which basically takes in a ClientId and ClientSecret and before any request is made, it checks if it has a valid Bearer Token - if not it will use the client…
Tom Glenn
  • 1,982
  • 4
  • 16
  • 26
23
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
  • 231
  • 1
  • 2
  • 4
23
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
  • 346
  • 1
  • 2
  • 7
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
  • 8,444
  • 6
  • 49
  • 82
22
votes
2 answers

RestSharp AddFile Using Stream

I am using RestSharp (version 105.2.3.0 in Visual Studio 2013, .net 4.5) to call a NodeJS hosted webservice. One of the calls I need to make is to upload a file. Using a RESTSharp request, if I retrieve the stream from my end into a byte array and…
Jason
  • 941
  • 1
  • 10
  • 19
21
votes
1 answer

IRestResponse could not be found

I have restsharp 107.1.2 loaded via nuget target framework is .net 6.0. The following code claims that IRestResponse reference is missing, though I feel like I'm following pretty close to the RestSharp documentation. What am I missing? using…
Julius Alexander
  • 431
  • 2
  • 6
  • 13
21
votes
2 answers

RestSharp - How do I get the numerical http response code?

I'm using the RestSharp HTTP client library for C#. How I would retrieve the actual numerical http response code? Not only do I not see a property containing the numerical code but I don't even see it in the headers collection.
Howiecamp
  • 2,981
  • 6
  • 38
  • 59
21
votes
4 answers

NTLM Authentication using RestSharp?

I am trying to use NTLM authentication for my REST calls to TeamCity using RestSharp. IRestClient _client=new RestClient(_url); _client.Authenticator = new NtlmAuthenticator …
pinaki
  • 251
  • 1
  • 3
  • 5
20
votes
2 answers

How do I use the cookie container with RestSharp and ASP.NET sessions?

I'd like to be able to call an authentication action on a controller and if it succeeds, store the authenticated user details in the session. However, I'm not sure how to keep the requests inside the session as I'm using RestSharp as a detached…
jaffa
  • 26,770
  • 50
  • 178
  • 289
20
votes
4 answers

debugger is looking for executioncontext.cs, how to fix?

I am debugging this code and getting a strange "source not found" page that is looking for this class called ExecutionContext.cs when the debugger lands on the Jtoken line. ExecutionContext.cs not found. You need to find the ExecutionContext.cs…
disq0
  • 801
  • 1
  • 6
  • 7
20
votes
3 answers

How to idiomatically handle HTTP error codes when using RestSharp?

I'm building an HTTP API client using RestSharp, and I've noticed that when the server returns an HTTP error code (401 Unauthorized, 404 Not Found, 500 Internal Server Error, etc.) the RestClient.Execute() doesn't throw an exception - instead I get…
Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197
20
votes
3 answers

RestSharp & TLS 1.1

Are there any known issues with using RestSharp & TLS 1.1? We currently use RestSharp to send post requests to a vendor. This vendor is no longer going to accept TLS 1.0 connections and changing to TLS 1.1. The problem is when they switch from TLS…
Jacob Dixon
  • 201
  • 1
  • 2
  • 4
19
votes
4 answers

C# Web Request w RestSharp - "The request was aborted: Could not create SSL/TLS secure channel"

I have an incredibly simple web request with RestSharp: var client = new RestClient("https://website.net"); var request = new RestRequest("/process", Method.GET); request.AddParameter("cmd", "execute"); IRestResponse response =…
Gerald
  • 521
  • 1
  • 6
  • 16
19
votes
3 answers

Issue with RestSharp installation in Visual-Studio 2013

I am trying to use RestSharp in my C# Visual-Studio 2013 project to POST data at a given URL. When i try to install the package via NuGet it gives me the following error: Installing 'RestSharp 106.1.0'. Successfully installed 'RestSharp…
Noel
  • 384
  • 1
  • 3
  • 16