restsharp

RestSharp Deserialization with JSON Array

青春壹個敷衍的年華 提交于 2019-11-30 14:38:18
问题 I have a JSON response that I'm trying to deserialize with RestSharp, and it looks like this: {"devices":[{"device":{"id":7,"deviceid":"abc123","name":"Name"}}, {"device":{"id":1,"deviceid":"def456","name":"Name"}}], "total":2, "start":0, "count":2} Based off of some suggestions I've found, I've tried to setup my POCO like this: public class DevicesList { public List<DeviceContainer> Devices; } public class DeviceContainer { public Device Device; } public class Device { public int Id { get;

RestSharp is loading the whole file into memory when uploading. How to avoid it?

陌路散爱 提交于 2019-11-30 14:03:46
I'm using RestSharp in a Mono project to upload some files and I have noticed that when a large file is uploaded, the memory grows substantially. Looking at RestSharp source code I did notice that FileParameter expects a byte array, which means it is really loading the file into memory. Am I doing something wrong? Is there a way for RestSharp not do this? I might be uploading really large files so, uploading them from memory is not an option. Any help (including telling me to use another HTTP library available on mono) is welcome. Use the AddFile(name, writer, filename) overload. For the

RestSharp client returns all properties as null when deserializing JSON response

别说谁变了你拦得住时间么 提交于 2019-11-30 08:46:17
I'm trying to do a very simple example of using RestSharp's Execute method of querying a rest endpoint and serializing to a POCO. However, everything I try results in a response.Data object that has all properties with a NULL value. Here is the JSON response: { "Result": { "Location": { "BusinessUnit": "BTA", "BusinessUnitName": "CASINO", "LocationId": "4070", "LocationCode": "ZBTA", "LocationName": "Name of Casino" } } } Here is my test code [TestMethod] public void TestLocationsGetById() { //given var request = new RestRequest(); request.Resource = serviceEndpoint + "/{singleItemTestId}";

How can I convert this .NET RestSharp code to Microsoft.Net.Http HttpClient code?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 07:16:33
I'm trying to figure out how to use HttpClient to POST some simple parameters. Email Password I've been doing this with RestSharp, but I'm trying to migrate off that. How can I do this with HttpClient , please? I have the following RestSharp code var restRequest = new RestRequest("account/authenticate", Method.POST); restRequest.AddParameter("Email", email); restRequest.AddParameter("Password", password); How can I convert that to use the (Microsoft.Net.Http) HttpClient class, instead? Take note: I'm doing a POST Also, this is with the PCL assembly. Lastly, can I add in a custom header. Say:

How can I deserialize Xml list using Restsharp?

时光怂恿深爱的人放手 提交于 2019-11-30 07:10:37
I have an xml like this <?xml version="1.0" encoding="utf-8"?> <xml> <item> <accountid>1</accountid> <accounttypeid>1</accounttypeid> <accounttypename/> <accountbankid>1</accountbankid> <accountbankname/> <accountsaldo>0</accountsaldo> </item> <item> <accountid>2</accountid> <accounttypeid>1</accounttypeid> <accounttypename/> <accountbankid>2</accountbankid> <accountbankname/> <accountsaldo>0</accountsaldo> </item> ... </xml> I want to deserialize this xml list to POCO object which is public class Account { public string AccountId { get; set; } public string AccountTypeId { get; set; } public

How to RestSharp add client certificate in Https request? (C#)

微笑、不失礼 提交于 2019-11-30 04:12:45
How to RestSharp add client certificate in Https request ? My code it doesn't work . public static IRestResponse<User> AsyncHttpRequestLogIn(string path, string method, object obj) { var client = new RestClient(Constants.BASE_URL + path); // https:.... var request = method.Equals("POST") ? new RestRequest(Method.POST) : new RestRequest(Method.GET); request.RequestFormat = RestSharp.DataFormat.Json; // The path to the certificate. string certificate = "cer/cert.cer"; client.ClientCertificates.Add(new X509Certificate(certificate)); request.AddBody( obj ); IRestResponse<User> response = client

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

亡梦爱人 提交于 2019-11-30 03:05:28
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: it's a console app, so I don't need bells and whistles. Ultimately, I want my app to

Deserializing a json string with newtonsoft or restsharp

北城余情 提交于 2019-11-29 22:16:42
I have a string that comes out of a database which is in Json format. I have tried to deserialize it with: RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer(); var x = deserial .Deserialize<Customer>(myStringFromDB) But the .Deserialize function expects an IRestResponse Is there a way to use RestSharp to just deserialize raw strings? I also have this problem, and I solve it using the Newtonsoft.Json . Include theses namespaces: using Newtonsoft.Json; using RestSharp; and try something like this: return JsonConvert.DeserializeObject<T>(response.Content); On the response

RestSharp print raw request and response headers

岁酱吖の 提交于 2019-11-29 20:45:01
I'm using RestSharp to make calls to a webservice. All is well but I was wondering if it would be possible to print the raw request headers and body that is sent out and the raw response headers and the response body that comes back. This is my code where I create a request and get a response back public static TResponse ExecutePostCall<TResponse, TRequest>(String url, TRequest requestData, string token= "") where TResponse : new() { RestRequest request = new RestRequest(url, Method.POST); if (!string.IsNullOrWhiteSpace(token)) { request.AddHeader("TOKEN", token); } request.RequestFormat =

RestSharp is loading the whole file into memory when uploading. How to avoid it?

岁酱吖の 提交于 2019-11-29 19:21:20
问题 I'm using RestSharp in a Mono project to upload some files and I have noticed that when a large file is uploaded, the memory grows substantially. Looking at RestSharp source code I did notice that FileParameter expects a byte array, which means it is really loading the file into memory. Am I doing something wrong? Is there a way for RestSharp not do this? I might be uploading really large files so, uploading them from memory is not an option. Any help (including telling me to use another HTTP