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
8
votes
1 answer

Upload File using RestClient as multipart/form-data in c#

I am trying to upload files from the c# class using restClient (RestSharp) request. I am creating Method.POST method and add one Audio file to this request As multipart/form-data. Server throws an exception when I execute the request. Exception : …
Ankit Patel
  • 191
  • 1
  • 1
  • 9
8
votes
1 answer

Using RestSharp to request a URL with Windows authentication

I have a web site in IIS that its Authentication mode is set to Windows. I need to call a URL in that site using restsharp : var client = new RestClient(item.Url); var request = new RestRequest("/account/Menu",…
mhesabi
  • 1,140
  • 3
  • 22
  • 48
8
votes
1 answer

RestSharp ignoring system proxy (for example Fiddler) on .NET Core

I want check the http traffic with Fiddler, but no any http traffic captured, my testing codes: private static void ByRestSharp() { var restClient = new RestClient("https://jsonplaceholder.typicode.com"); var request = new…
Liu Peng
  • 1,226
  • 2
  • 11
  • 13
8
votes
1 answer

Converting code from RestSharp to HttpClient

Could someone please help me convert this ASP .Net Core example (to be used in my Web Api to consume a management API from Auth0) which uses RestSharp into one using HttpClient? var client = new…
Fabricio Rodriguez
  • 3,769
  • 11
  • 48
  • 101
8
votes
2 answers

HttpClient- adding parameters to Get request

I have a RestRequest which I am trying to convert to HttpClient Get request. Is there any way I can send parameters the way it is done below? private readonly IRestClient _restClient; public Type GetInfo(string name) { var request = new…
legend
  • 91
  • 1
  • 1
  • 3
8
votes
2 answers

Could not load type 'RestSharp.Authenticators.HttpBasicAuthenticator' from assembly 'RestSharp, Version=105.1.0.0

I have used a MVC web application running on the ASP.NET Framework version 4.5.1. I have made nopcommercePlugin. I am upgrading version 3.4 to 3.5 After the update, I am getting the following error: System.TypeLoadException: Could not load type …
Ajisha
  • 413
  • 6
  • 22
8
votes
1 answer

Restsharp- Method.POST is not working

I have tried all possible scenarios as per RestSharp.org documentation but no luck! I have ASP.Net Web API here is the POST resource [Route("/api/saveperson/{name}/{fathername}")] public void Post([FromBody]CustomObject customObject, string…
Gaurav Arora
  • 2,243
  • 6
  • 40
  • 57
8
votes
3 answers

In C#, how do I model a JSON object with multiple nested arrays?

I am getting this JSON response from a system I am connecting to and trying to figure out the best way to deserialize it into a C# object. I am currently using RestSharp which seems pretty straight forward to use but the format of the JSON is…
leora
  • 188,729
  • 360
  • 878
  • 1,366
8
votes
1 answer

Deserialize JSON dynamically to derived types based on content?

In my little library I'm writing as a side project, I'm using RestSharp to get Json from a web API. The deserialization into model classes works fine for simple types, but there are endpoints where the resulting type is unknown (or unclear) at…
MrFloya
  • 137
  • 2
  • 10
8
votes
1 answer

RestSharp Accept header change

I am using RestSharp for developing on the client side. I am also using Ruby Grape gem for my custom API on server side. Grape gem can do versioning by setting Accept HTTP header f.e to application/vnd.twitter-v1+json And test command via console…
Ihor
  • 91
  • 1
  • 1
  • 6
8
votes
2 answers

RestSharp RestRequest.AddBody not using Newton.Json attributes

var obj = new MyObject(); I am having an issue getting RestSharp RestRequest.AddBody(obj); to serialize the object correctly. class MyObject { [JsonProperty(PropertyName="a")] public A{get;set;} [JsonProperty(PropertyName="b")] public…
Ryan Fisch
  • 2,614
  • 5
  • 36
  • 57
8
votes
1 answer

How do I save cookies from RestResponse and pass them to the next RestRequest?

If anyone could help me out with my issue, I would be really thankful. I have written a C# code using RestSharp library to interact with RightScale API. The code works fine with one set of username and password, but when I replace the username and…
user1548923
  • 81
  • 2
  • 5
7
votes
3 answers

Contrary to RestSharp docs, request.AddFile does not accept FileParameter as argument for AddFile. Can't find any docs on how to migrate. Any ideas?

Ok so here's the C# code that's breaking since I updated RestSharp to the current version: restRequest.Files.Add((FileParameter)file); // Added cast for clarity According to the the current official documentation, this is the correct…
Kris Craig
  • 558
  • 1
  • 7
  • 19
7
votes
4 answers

Serialize an object when posting data with RestSharp

I've recently started using RestSharp to consume a REST service which uses XML. It makes deserializing objects from XML to a collection of custom objects trivial. But my question is what is the best way to reserialize when posting back to the…
Evan
  • 4,450
  • 10
  • 40
  • 58
7
votes
1 answer

RestSharp body always empty

I need to call a Post service with RestSharp var client = new RestClient(url); var request = new RestRequest(url,Method.POST); request.AddHeader("Content-type", "application/json"); request.AddJsonBody(new { grant_type = "client_credentials",…
Lamloumi Afif
  • 8,941
  • 26
  • 98
  • 191