restsharp

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

扶醉桌前 提交于 2019-12-06 01:39:47
问题 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) { var client = CreateRestClient(); var request = new RestRequest(resource, method) { RequestFormat =

Unable to send cookies with RestSharp

不羁的心 提交于 2019-12-06 00:07:54
问题 I have been trying to access a REST-based API on a Windows Phone using a few different approaches, but I seem to be running into issues with attaching cookies to the request with all of them. I have tried the WebClient approach (which now seems to have become marked SecurityCritical, so you can no longer inherit from it and add code). I looked briefly at HttpWebRequest which seemed cumbersome at best. Now I am using RestSharp which seems decent to use, but I am still having problems with my

Converting HttpClient to RestSharp

为君一笑 提交于 2019-12-06 00:02:14
问题 I have Httpclient functions that I am trying to convert to RestSharp but I am facing a problem I can't solve with using google. client.BaseAddress = new Uri("http://place.holder.nl/"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",access_token); HttpResponseMessage response = await client.GetAsync("api/personeel/myID"); string resultJson = response.Content.ReadAsStringAsync().Result; This Code is in my HttpClient code, which works good, but I can't get it

Cancel a RestSharp Request

送分小仙女□ 提交于 2019-12-05 23:33:55
I'm making a wp7 app that uses RestSharp to download some data. I noticed the application guidelines require that I provide a ui element that allows the user to cancel a data transfer. Is it possible to cancel an ExecuteAsync request with rest sharp? ExecuteAsync() returns an RestRequestAsyncHandle which has an Abort() method you can call to kill the request. 来源: https://stackoverflow.com/questions/9216062/cancel-a-restsharp-request

Deserialize nested JSON Response with RestSharp Client

ⅰ亾dé卋堺 提交于 2019-12-05 21:12:35
I'd like to consume a REST Api and deserialize the nested JSON Response. For that purpose I tried to create some POCO classes which represent the JSON Response [1]. The response looks like this: { "success": true, "message": "OK", "types": [ { "name": "A5EF3-ASR", "title": "ITIL Foundation Plus Cloud Introduction", "classroomDeliveryMethod": "Self-paced Virtual Class", "descriptions": { "EN": { "description": "some Text null", "overview": null, "abstract": "Some other text", "prerequisits": null, "objective": null, "topic": null } }, "lastModified": "2014-10-08T08:37:43Z", "created": "2014-04

Can RestSharp send a List<string> in a POST request?

血红的双手。 提交于 2019-12-05 19:34:48
问题 I am trying to get RestSharp to work with a restful service that I have. Everything seems to be working fine, except when my object being passed via POST contains a list (in this particular case a list of string ). My object: public class TestObj { public string Name{get;set;} public List<string> Children{get;set;} } When this gets sent to the server the Children property gets sent as a string with the contents System.Collections.Generic.List`1[System.String] . This is how I am sending the

Why is RestSharp deserializing two dates differently?

﹥>﹥吖頭↗ 提交于 2019-12-05 12:26:32
I have a rest call that returns this (using Advance Rest Client in Chrome to do testing): MyObject: [22] 0: { ID: "123456" UTC1: "2013-04-19T03:12:32Z" UTC2: "2013-04-19T03:12:36.994Z" } The code that grabs the response and serializes it to an object looks like this: IRestResponse<List<MyObject>> response = client.Execute<List<MyObject>>(request); When I look at the response object one of the dates is wrong. If I inspect it or use the objects in any way I get this: UTC1: 4/19/2013 3:12 UTC2: 4/18/2013 9:12:36 PM <--CONVERTED!! I need both to be serialized as the time that is returned in the

Difference between RestSharp methods AddParameter and AddQueryParameter using HttpGET

a 夏天 提交于 2019-12-05 10:22:41
问题 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 response = client.Execute(request); This doesn't: var client = new RestClient(apiUrl); var request = new RestRequest(myurl, Method.GET); foreach (var param in parameters) { request.AddParameter(param.Key, param.Value); } var response = client.Execute(request);

How do I use PUT in RestSharp?

落花浮王杯 提交于 2019-12-05 10:20:32
I want to use PUT, but I can only find examples of how to use POST. The json data I want to send is sent using this cURL command curl -i -H "Content-Type: application/json" -X PUT -d {"status":1}'http://192.168.0.3:1337/auto/api/v1.0/relays/3 Also I want the "1" after status and the last "3" to be variables. Set the method as you create the rest request: public void Update(int id, Product product) { var request = new RestRequest("Products/" + id, Method.PUT); request.AddJsonBody(product); client.Execute(request); } ( Source ) (Aircode Warning) var status = 1; var id = 3; var request = new

Passing list of int to Web API from RestSharp Client

若如初见. 提交于 2019-12-05 10:09:46
When I use code below from REST Sharp I am not able to pass listOfSelectedTicketsIds it always null. Request of Rest Sharp .net Client var _stDeveloperApi = new RestClient("http://127.0.0.1/"); var url = string.Format("api/v1/SignalR/MultiClickMode"); var listOfSelectedTicketsIds = new List<int> { 2, 3 }; var request = new RestRequest(url, Method.GET); request.AddParameter("listOfSelectedTicketsIds", listOfSelectedTicketsIds, ParameterType.GetOrPost); var response = _stDeveloperApi.Execute(request); Web API Method [HttpGet] public HttpResponseMessage MultiClickMode(List<int>