restsharp

Converting a JToken (or string) to a given Type

吃可爱长大的小学妹 提交于 2019-12-28 11:42:39
问题 TL;DR Version I have a object of type JToken (but can also be a string ) and I need to convert it into a Type contained in the type variable: Type type = typeof(DateTime); /* can be any other Type like string, ulong etc */ var obj = jsonObject["date_joined"]; /* contains 2012-08-13T06:01:23Z+05:00 */ var result = Some_Way_To_Convert(type, obj); The above result should be a DateTime object with the value given in date_joined . Full Story I'm using both RestSharp and Json.NET in a Windows Phone

Converting a JToken (or string) to a given Type

南楼画角 提交于 2019-12-28 11:42:09
问题 TL;DR Version I have a object of type JToken (but can also be a string ) and I need to convert it into a Type contained in the type variable: Type type = typeof(DateTime); /* can be any other Type like string, ulong etc */ var obj = jsonObject["date_joined"]; /* contains 2012-08-13T06:01:23Z+05:00 */ var result = Some_Way_To_Convert(type, obj); The above result should be a DateTime object with the value given in date_joined . Full Story I'm using both RestSharp and Json.NET in a Windows Phone

How to use RestSharp with async/await

落爺英雄遲暮 提交于 2019-12-28 09:31:13
问题 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). 回答1: 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

How to Deserialize a Json Array with C#?

不问归期 提交于 2019-12-27 06:16:16
问题 I use RestSharp to make a Rest API Call. public class GetValues { public string Values{ get; set; } } public class JsonObjects { public List<GetValues> Values{ get; set; } } RestRequest restRequest = new RestRequest("api/tempCatalog/temp1", Method.GET); restRequest.AddHeader("Accept", "application/json"); restRequest.AddHeader("Content-Type", "application/json"); restRequest.AddHeader("Authorization", token); IRestResponse restResponse = clientRest.Execute(restRequest ); string Content =

How to Deserialize a Json Array with C#?

余生长醉 提交于 2019-12-27 06:14:04
问题 I use RestSharp to make a Rest API Call. public class GetValues { public string Values{ get; set; } } public class JsonObjects { public List<GetValues> Values{ get; set; } } RestRequest restRequest = new RestRequest("api/tempCatalog/temp1", Method.GET); restRequest.AddHeader("Accept", "application/json"); restRequest.AddHeader("Content-Type", "application/json"); restRequest.AddHeader("Authorization", token); IRestResponse restResponse = clientRest.Execute(restRequest ); string Content =

XML attributes deserialization with RestSharp

倖福魔咒の 提交于 2019-12-25 09:39:25
问题 I have the following xml and I'm trying to deserialize it. I have used the RestSharp library but with this particular response I'm getting an empty list of resources. Do you know if the library has problem with self-closing elements in XML? <?xml version="1.0" encoding="utf-8"?> <resourceList xmlns="..." xmlns:xsi="..." xsi:schemaLocation="..." location="..."> <resourceURL location="../../../campaign/12" metaData1="12" metaData2="ACD Systems" metaData3="CPS" metaData4="Active" metaData5=

XML attributes deserialization with RestSharp

谁都会走 提交于 2019-12-25 09:39:23
问题 I have the following xml and I'm trying to deserialize it. I have used the RestSharp library but with this particular response I'm getting an empty list of resources. Do you know if the library has problem with self-closing elements in XML? <?xml version="1.0" encoding="utf-8"?> <resourceList xmlns="..." xmlns:xsi="..." xsi:schemaLocation="..." location="..."> <resourceURL location="../../../campaign/12" metaData1="12" metaData2="ACD Systems" metaData3="CPS" metaData4="Active" metaData5=

Consuming Drupal RestApi with c#

南楼画角 提交于 2019-12-25 08:45:39
问题 I am working to consume Drupal Rest Api using c#. I am using drupal 7.5 and utilising it's rest services/api following various resources. I have been successful with google's postman to post the content but when I try to replicate it with c# code I am prompted with forbidden error saying: Access denied for user anonymous. I am utilising rest-sharp to consume this API. I have researched quite a lot and haven't found solution yet,as well as haven't noticed anyone doing this work in c#.

C# RestSharp ignoring timeout parameter?

随声附和 提交于 2019-12-25 00:58:22
问题 I have a C# function that checks to see whether or not a proxy is valid by trying to connect to the REST API at https://jsonplaceholder.typicode.com/. However, the RestClient seems to be ignoring the 5000ms timeout value I gave it, and instead using a (default?) timeout of 2100ms. Here's my function: private bool checkProxy(ProxyHolder ph) { bool success = false; String errorMsg = ""; Stopwatch sw = new Stopwatch(); WebProxy wp = new WebProxy(ph.ip, ph.port); try { sw.Start(); IRestResponse

Does RestSharp not support Windows Phone 8?

核能气质少年 提交于 2019-12-24 23:03:29
问题 I've always used RestSharp to handle async requests on Windows Phone 7 & 7.8 applications, but today, I was trying to add RestSharp to a Windows Phone 8 application and it wouldn't work. This is the error received: Install-Package: Unable to install the package "RestSharp 104.1". You are attempting to install this package to a will "WindowsPhone, Version = v8.0" as the target of the project, but this package does not contain any compatible with the framework assembly references 回答1: I got