restsharp

Set 'Content-Type' header using RestSharp

自闭症网瘾萝莉.ら 提交于 2019-11-28 08:04:46
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 my code looks like: RestRequest request = new RestRequest("/v2/starred_entries.json", Method.POST); request.AddHeader("Content-Type", "application/json; charset=utf-8"); request.RequestFormat = DataFormat.Json; request.AddParameter("starred_entries", id); //Pass the request to the RestSharp client Messagebox.Show(rest.ExecuteAsPost(request, "POST")

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

☆樱花仙子☆ 提交于 2019-11-28 05:21:17
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 HarooApi { const string BaseUrl = "https://domain.here"; readonly string _accountSid; readonly string _secretKey; public HarooApi(string accountSid, string secretKey) { _accountSid = accountSid; _secretKey = secretKey; } public T Execute<T>(RestRequest request) where T : new() { var client = new RestClient(); client.BaseUrl = BaseUrl; client

How to use RestSharp with async/await

↘锁芯ラ 提交于 2019-11-28 05:09:40
I'm struggling to find a modern example of some asynchronous C# code that uses RestSharp with async and await . I know there's been a recent update by Haack but I don't know how to use the new methods. Also, how can I provide a cancellation token so that the operation can be canceled (say, if a person is sick of waiting and presses the Cancel button in the app's UI). Erik Schierboom Well, the update Haack is referring to has been made by me :) So let me show you how to use it, as it is actually very simple. Previously you had methods like ExecuteAsyncGet that would return a RestSharp custom

How to POST request using RestSharp

╄→尐↘猪︶ㄣ 提交于 2019-11-27 21:06:06
I m trying to POST the request using RestSharp client as follows I m passing the Auth Code to following function public void ExchangeCodeForToken(string code) { if (string.IsNullOrEmpty(code)) { OnAuthenticationFailed(); } else { var request = new RestRequest(this.TokenEndPoint, Method.POST); request.AddParameter("code", code); request.AddParameter("client_id", this.ClientId); request.AddParameter("client_secret", this.Secret); request.AddParameter("redirect_uri", "urn:ietf:wg:oauth:2.0:oob"); request.AddParameter("grant_type", "authorization_code"); request.AddHeader("content-type",

How do I get an OAuth 2.0 authentication token in C#

点点圈 提交于 2019-11-27 20:43:13
问题 I have these settings: Auth URL (which happens to be a "https://login.microsoftonline.com/...") if that helps. Access Token URL "https://service.endpoint.com/api/oauth2/token" ClientId "abc" Clientsecret "123" I then need to make a get call using a bearer token in the header. I can get this to work in Postman, but have hit a wall trying to work out how to implement it in C#. I've been using RestSharp (but open to others). It all seems so opaque, when I thought it'd be pretty straight forward:

Are these the main differences between RestSharp and ServiceStack's Client Code? [closed]

拟墨画扇 提交于 2019-11-27 11:27:56
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 using ServiceStack for my service). Here is what I have so far (differences only). The list is fairly small as they are indeed very similar: ServiceStack Pros Fluent Validation from my already created service POCO objects One API for both client and service Code reads better (i.e. Get<>(), Post<>()) Cons Some of my strings must be written out (i.e. If

Deserialize JSON with dynamic objects

浪尽此生 提交于 2019-11-27 06:43:20
问题 I have a JSON object that comes with a long list of area codes. Unfortunately each area code is the object name on a list in the Data object. How do I create a class that will allow RestSharp to deserialize the content? Here's how my class looks now: public class phaxioResponse { public string success { get; set; } public string message { get; set; } public List<areaCode> data { get; set; } public class areaCode { public string city { get; set; } public string state { get; set; } } } And here

RestSharp serialization to JSON, object is not using SerializeAs attribute as expected

那年仲夏 提交于 2019-11-27 05:04:48
I am using RestSharp (version 104.4 via NuGet) to make calls to a Rest Web Service. I have designed a set of objects (POCO) which matches resources exposed in the API. However, my objects property names does not match those expected by the Rest Service when posting data, so I would like to "transform" them when I make a request to the Rest service to make them match match. I read that adding SerializeAs attribute (with a Name specified) on my POCO's property will make them serialize correctly, but it won't. My POCO Imports RestSharp.Serializers <Serializable(), SerializeAs(Name:="ApiMember")>

RestSharp post request - Body with x-www-form-urlencoded values

≡放荡痞女 提交于 2019-11-27 02:09:27
问题 I am using postman and making an api post request where I am adding body with x-www-form-urlencoded key/values and it works fine in postman. The issue arrises when I try it from c# using RestSharp package. I have tried the following code below but not getting the response. I get "BadRequest" invalid_client error. public class ClientConfig { public string client_id { get; set; } = "value here"; public string grant_type { get; set; } = "value here"; public string client_secret { get; set; } =

Set 'Content-Type' header using RestSharp

回眸只為那壹抹淺笑 提交于 2019-11-27 02:03:38
问题 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 my code looks like: RestRequest request = new RestRequest("/v2/starred_entries.json", Method.POST); request.AddHeader("Content-Type", "application/json; charset=utf-8"); request.RequestFormat = DataFormat.Json; request.AddParameter("starred_entries",