restsharp

Unable to send cookies with RestSharp

狂风中的少年 提交于 2019-12-04 04:52:17
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 cookies not being added to the request when it's sent. My code is as follows: // ... some additional

RestSharp Accept header change

前提是你 提交于 2019-12-04 04:12:08
I am using RestSharp for developing on the client side. I am also using Ruby Grape gem for my custom API on server side. Grape gem can do versioning by setting Accept HTTP header f.e to application/vnd.twitter-v1+json And test command via console works perfect curl -H Accept=application/vnd.twitter-v1+json /statuses/public_timeline But when I am trying to set up header for RestRequest I am getting error 404 on the server. I have no idea why so. I have found another issue that server returns 406 error - but in my case 404. How can I put custom value for Accept header? You can set a custom

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

折月煮酒 提交于 2019-12-04 03:52:38
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 object: var client = new RestClient(); var request = new RestRequest("http://localhost", Method.PUT); var

RestSharp Serialize/Deserialize Naming Conversion

跟風遠走 提交于 2019-12-04 03:43:28
问题 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 also case-sensitive. I would like to be able to provide a CallRequest Class, wrapping the data required in my preferred naming conventions, and then

RestSharp ignoring system proxy (for example Fiddler) on .NET Core

纵饮孤独 提交于 2019-12-04 03:15:37
问题 I want check the http traffic with Fiddler, but no any http traffic captured, my testing codes: private static void ByRestSharp() { var restClient = new RestClient("https://jsonplaceholder.typicode.com"); var request = new RestRequest("posts", Method.GET); var response = restClient.Get<List<Post>>(request); Console.WriteLine("{0} posts return by RestSharp.", response.Data.Count); } But after I changed to use HttpClient, Fiddler can capture the http traffic, sample codes: private static void

Testing the Deserialization of RestSharp without proper REST-Api

一笑奈何 提交于 2019-12-04 01:34:55
问题 EDIT: The solution to the question can be found in the first comment by John Sheehan! i would like to use Restsharp as Rest-Client for my Project. Since the REST server is not running yet, I would like to test the client without the Server. My main focus is on the deserialization of the returning XML-Response. Is it possible to deserialize XML using RestSharp without a proper RestSharp.RestResponse? I tried it like this: public void testDeserialization() { XmlDeserializer d = new

Why is my Initial call in RestSharp really slow? but others after are very fast

南笙酒味 提交于 2019-12-04 01:26:09
I am making calls to a WEB API using RESTSHARP and they work fine. However, the Initial call to the API (regardless of what call it is) can sometimes take up to 10 seconds to get a response. Every other call after that is really quick. Does anyone know a way around this? I am running a WPF 4.0 application code: var client = new RestClient(apiAddress); var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); skrause It's most likely the network settings causing this problem. I recently had the same issue and it turned out that when using HttpWebRequest or

Serialize an object when posting data with RestSharp

喜你入骨 提交于 2019-12-04 01:24:44
问题 I've recently started using RestSharp to consume a REST service which uses XML. It makes deserializing objects from XML to a collection of custom objects trivial. But my question is what is the best way to reserialize when posting back to the service? Should I use LINQ-to-XML to reserialize? I tried using the Serializeable attribute and a SerializeToXml utility function, but when I do so it seems to break the deserializing performed by RestSharp. 回答1: I have been able to use attributes to get

Difference between RestSharp methods AddParameter and AddQueryParameter using HttpGET

可紊 提交于 2019-12-04 00:20: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); Resulting in: System.Exception: API Call MyWebAPIMethod GET: Failed with status code 0 - Unable to

RestSharp deserialize JSON content(represent an object contains an byte array) error

こ雲淡風輕ζ 提交于 2019-12-03 22:46:24
The Client side receives a formal JSON content "{\"Id\":[1,2,3],\"Size\":56}" , but get an error in deserialization the byte array. 1 Error occurs in the statement below IRestResponse<key> response = client.Execute<key>(request); 2 Error message is "No parameterless constructor defined for this object." 3 The object class in client size is the same as it's in server side: public class key { public byte[] id { get; set; } public int Size { set; get; } } 4 I've tried passing object that contains string and integer by JSON format and that's all fine but byte array. JsonDeserializer from RestSharp