restsharp

Xml Sequence deserialization with RestSharp

别等时光非礼了梦想. 提交于 2019-11-29 16:06:01
I have this xml feed from an API with a XML sequence. <?xml version="1.0" encoding="UTF-8" ?> <Function> <Cmd>2002</Cmd> <Status>1</Status> <Cmd>2003</Cmd> <Status>0</Status> <Cmd>2004</Cmd> <Status>0</Status> <Cmd>1012</Cmd> <Status>3</Status> <Cmd>2006</Cmd> <Status>0</Status> <Cmd>2007</Cmd> <Status>0</Status> ... </Function> I already tried a few options for deserialization with Restsharp. Ideally I would like to have something like the following, but it's obviously not working. public class MyResponse { public List<Setting> Settings { get; set;} } public class Setting { public int Cmd {

How can I deserialize Xml list using Restsharp?

筅森魡賤 提交于 2019-11-29 09:15:27
问题 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

Does RestSharp overwrite manually set Content-Type?

微笑、不失礼 提交于 2019-11-29 06:21:02
问题 I'm creating a RestSharp.RestRequest via: RestRequest request = new RestRequest(); request.Method = Method.POST; request.Resource = "/rest-uri"; request.AddHeader("Content-Type", "application/someContentType"); string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + Environment.NewLine + "<register-request">" + Environment.NewLine + " <name=\"someName\"/>" + Environment.NewLine + "</register-request>"); request.AddParameter("text/xml", registerSinkRequest, ParameterType

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

≯℡__Kan透↙ 提交于 2019-11-29 01:38:04
问题 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

RestSharp Post a JSON Object

社会主义新天地 提交于 2019-11-29 01:19:02
I am trying to post the following JSON with RestSharp: {"UserName":"UAT1206252627", "SecurityQuestion":{ "Id":"Q03", "Answer":"Business", "Hint":"The answer is Business" }, } I think that I am close, but I seem to be struggling with the SecurityQuestion (the API is throwing an error saying a parameter is missing, but it doesn't say which one) This is the code I have so far: var request = new RestRequest("api/register", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("UserName", "UAT1206252627"); SecurityQuestion securityQuestion = new SecurityQuestion("Q03");

Can RestSharp send binary data without using a multipart content type?

冷暖自知 提交于 2019-11-28 20:51:22
I have been using AddParameter to include XML bodies in my HTTP requests: request.AddParameter(contentType, body, ParameterType.RequestBody); However, this does not seem to work for non-string bodies. (RestSharp's Http.RequestBody is a string for some reason.) I tried using AddFile() , but I can't find any way to avoid encoding the "file" as multipart/form , even if I've only supplied a single object. I'm not at all opposed to underhanded reflection to solve this problem, but I'm hoping to avoid modifying the source just to send arbitrary data in an HTTP request. Edit: regarding the requests I

Converting a JToken (or string) to a given Type

拥有回忆 提交于 2019-11-28 19:03:51
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 project and I'm stuck while trying to deserialize JSON responses from a REST API. What I'm actually

Deserializing a json string with newtonsoft or restsharp

守給你的承諾、 提交于 2019-11-28 18:55:57
问题 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? 回答1: I also have this problem, and I solve it using the Newtonsoft.Json. Include theses namespaces: using Newtonsoft.Json; using RestSharp

How to add text to request body in RestSharp

送分小仙女□ 提交于 2019-11-28 16:06:46
问题 I'm trying to use RestSharp to consume a web service. So far everything's gone very well (cheers to John Sheehan and all contributors!) but I've run into a snag. Say I want to insert XML into the body of my RestRequest in its already serialized form (i.e., as a string). Is there an easy way to do this? It appears the .AddBody() function conducts serialization behinds the scenes, so my string is being turned into <String /> . Any help is greatly appreciated! EDIT: A sample of my current code

Xml Sequence deserialization with RestSharp

为君一笑 提交于 2019-11-28 09:38:25
问题 I have this xml feed from an API with a XML sequence. <?xml version="1.0" encoding="UTF-8" ?> <Function> <Cmd>2002</Cmd> <Status>1</Status> <Cmd>2003</Cmd> <Status>0</Status> <Cmd>2004</Cmd> <Status>0</Status> <Cmd>1012</Cmd> <Status>3</Status> <Cmd>2006</Cmd> <Status>0</Status> <Cmd>2007</Cmd> <Status>0</Status> ... </Function> I already tried a few options for deserialization with Restsharp. Ideally I would like to have something like the following, but it's obviously not working. public