FAQ Database Discussion Community


How to solve UnsupportedMediatType when using RestSharp and OAuth2

c#,rest,oauth-2.0,restsharp
Just a few minutes ago I managed to make my code work with RestSharp and OAuth2, retrieving an access token. I now want to use that token on every call that I make to my REST API. Unfortunately I keep getting an UnsupportedMediaType StatusCode although the response status is completed....

Properly format json payload

c#,json,restsharp
I am trying to format json payload as such, but i am getting a syntax error at the Params property mailer.send2(new PayoutEmailModel { medium = "email", name = "sap_finance_supplier_payout", @params = @"{""supplier"":""" + BeneficiaryName + """,""lastfourdigits"":""" + AccountNo + """,""amount"":""" + Amount + """,""valuedate"":""" + BeneficiaryName + """,""time"":""" + BeneficiaryName...

RestSharp Serialize/Deserialize Naming Conversion

c#,json,serialization,restsharp,plivo
I am attempting to wrap the Plivo API (yes I'm aware it's been done) using RestSharp. However, I cannot find a method to translate the API Naming conventions to my own, for example: A "Call` (https://www.plivo.com/docs/api/call/#make-an-outbound-call) requires a minimum of: to, from, and answer_url parameters be provided. These parameters are...

how do use RESTSHARP send parameter JSON in this formatted JSON sub

c#,.net,json,restsharp
I use c# and use Restsharp in method request.AddBody() I want to this format { "boss":[{ "cus":"454", "date":"July 23,2015", "mangpo":"9.1", "namo":"rattatrayaya" }] } But my code: request.AddBody( new { boss = new []{"cus":"454","date":"July23,2015","mangpo":"9.1","namo":"rattatrayaya"} }); out put json to sent wrong not have "[": "boss":{ "cus":"454", "date":"July 23,2015", "mangpo":"9.1", "namo":"rattatrayaya" }...

error getting the api key using restsharp

c#,json,asp.net-web-api,restsharp
I was not able to retrieve my api key and user id. I used the Console.WriteLine to check my values, and they were just empty. Shouldn't I be able to retrieve those values? var client = new RestClient("http://myproject/"); var request = new RestRequest("api/ApiKey?email=" + email + "&password=" + password, Method.GET);...

How do I just get a list of JSON objects from RestSharp?

c#,json,restsharp
I am calling a WinApi 2.0 server using RestSharp and I get the following response: [ { "ItemSubType": "Base" }, { "ItemSubType": "Tall" }, { "ItemSubType": "Uppers" } ] I just need the three strings ["Base,"Tall","Uppers"]. What I would like is to get a list or array or enumerable sequence...

What is default timeout value of RestSharp RestClient?

http,timeout,restsharp,rest-client
Anybody aware of default timeout value of RestSharp RestClient ?

Problems Deserializing Nested JSON Array in C#

c#,json,json.net,restsharp
Edit I notice this is getting negative votes, I imagine it's for not showing research effort. I've looked at a lot of stack overflow posts. I can't find an example with JSON this heavily nested that has been accessed with examples of how the data stored in the JSON has...

RestSharp Moq Object Null Exception C# REST Unit Test

c#,rest,nunit,moq,restsharp
I'm having difficulties trying to figure this out. Any help is greatly appreciated. My restClient.Object gets a null exception. When I inspect the .Object of the restClient I get Message: Exception has been thrown by the target of an invocation. Inner Exception: Value cannot be null.Parameter name: source Stack Trace:...

Returning a simple Guid with RestSharp

c#,restsharp
RestSharp is unable to deserialize a response of a plain Guid. [Route("User/BeginSession")] [HttpGet] public Guid BeginSession() { return Guid.NewGuid(); } This test fails: [Fact] public void BeginSession_MadeAsARestRequest_Succeeds() { var client = new RestClient("http://localhost/xyz"); var request = new RestRequest("User/BeginSession"); var a = client.Execute(request); var result = client.Execute<Guid>(request).Data; Assert.NotEqual( Guid.Parse("{00000000-0000-0000-0000-000000000000}"), result); }...

Dynamically deserializing to a property in RestSharp

c#,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" } }, { project: { name: "Test 2" }] In RestSharp,...

RestRequest and Square Connect

c#,restsharp,square-connect
I am running the following code: var client = new RestClient(); var request = new RestRequest("https://connect.squareup.com/v1/me/payments", Method.GET) { RequestFormat = DataFormat.Json }; request.AddHeader("Authorization", "Bearer XXXXXX"); var Response = client.Execute(request); The response error message states: Value cannot be null. Parameter name: uri Not sure why I'm getting this error...

RestSharp defaulting Content-Type to application/x-www-form-urlencoded on POST

c#,restsharp
RestSharp seems to not allow me to override the Content-Type for a post request. I've followed the directions found here to no avail. I've also tried manually setting the header content type to application/json via request.AddHeaders("content-type", "application/json"); Examples of the request execution: private IRestResponse ExecuteRequest<T>(string resource, Method method, T model)...

RestSharp Authenticator Follow 302 Redirect

c#,.net,restsharp
I am trying to make requests to an API with RestSharp. This API is secured by redirecting the request to a login server, authenticate with basic credentials, obtain cookies, then redirect back to the API. I am afraid i have no control over the this. So the sequence of requests...

ON c# I'm use Restsharp read data json client.Execute(request); why show format XML how do show format JSON

c#,json,xml,restsharp
ON c# I'm use Restsharp read data json client.Execute(request), why show format XML how do show format JSON my code below: var client = new RestClient("http://omnamashiva"); var request = new RestRequest("/omnamashivaya.json", Method.GET); request.RequestFormat = DataFormat.Json; IRestResponse response = client.Execute(request); var content = response.Content; Console.WriteLine(content.ToString()); and I'm very confused. Why client.Execute(request)...

Deserialize JSON into Models that render in partial view (restsharp or any other method)

c#,json,asp.net-mvc,restsharp
I've never dealt with deserializing JSON and i'm just not getting it. I call an API and get JSON returned, I then want to use the JSON data my partial view. My thought process is get JSON, deserialize into Model, pass model to view and away we go. I've currently...

Unit testing MassTransit consumers that make utilize asynchronous calls

c#,asynchronous,async-await,restsharp,masstransit
We are using MassTransit asynchronous messaging (on top of RabbitMQ) for our microservice architecture. We ran into issues testing consumers that in turn make asynchronous calls. The example below shows a simple MassTransit consumer that uses RestSharp to make an outbound call and utilized the ExecuteAsync asynchronous method. public class...

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

c#,http,restsharp
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....

parse strange JSON response as List

c#,asp.net,json,restsharp
I am calling a webservice using RestSharp and getting my response back properly but the data I get back is in kind of a weird format. It is a list of GUIDS which is also what I want but they come back as a bool object or something, have a...

Converting PHP array of arrays to C#

c#,php,json.net,restsharp
I am writing a C# client for a 3rd party API (I'm using the RestSharp nuget package). Their documentation contains PHP examples which I must translate to C#. Most of their samples are simple enough and I have been able to convert them to C# but I am struggling with...

RestSharp.Portable HttpRequestException 500 (Internal Server Error) on iOS POST Request

ios,web-services,rest,xamarin,restsharp
I am using the RestSharp.Portable PCL because I am building a cross-platform service manager that will wrap and make calls to RestSharp regardless of the platform I am on. I am trying to POST data using a Xamarin iOS unit test project and I can successfully make GET requests but...

Uploading an IMG file through RestSharp

c#,xamarin,restsharp
I have the code: request.AddFile ("image_request[image]", ("picture.jpg"); The "image_request[image]" is required for the specific API. The "picture.jpg" is in my /resources/ folder and correctly works. However, with my application, I do not have a file stored locally. I take a picture with the camera app and have it stored as...