Tag: restsharp

使用RestSharp为Etsy的API获取signature_invalid调用oauth / request_token

我正在尝试使用RestSharp来访问Etsy的API。 以下是我尝试获取OAuth访问令牌的代码: var authenticator = OAuth1Authenticator.ForRequestToken( ConfigurationManager.AppSettings[“ApiKey”], ConfigurationManager.AppSettings[“ApiSecret”]); // same result with or without this next line: // authenticator.ParameterHandling = OAuthParameterHandling.UrlOrPostParameters; this.Client.Authenticator = authenticator; var request = new RestRequest(“oauth/request_token”) .AddParameter(“scope”, “listings_r”); var response = this.Client.Execute(request); Etsy告诉我签名无效。 有趣的是,当我将请求生成的时间戳和现时值输入到此OAuth签名validation工具中时 ,签名不匹配。 此外,该工具生成的URL与Etsy一起使用,其中RestSharp生成的URL不支持。 有什么我做错了或我需要用RestSharp配置的其他东西? 注意:我正在使用他们的Nuget包提供的RestSharp版本,该版本在发布时为102.5。

如何在Https请求中添加RestSharp添加客户端证书? (C#)

如何在Https请求中添加RestSharp添加客户端证书? 我的代码不起作用。 public static IRestResponse 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 response = client.Execute(request); return response; […]

使用RestSharp进行Xml序列反序列化

我有一个带有XML序列的API的xml feed。 2002 1 2003 0 2004 0 1012 3 2006 0 2007 0 … 我已经尝试了一些使用Restsharp进行反序列化的选项。 理想情况下,我希望有类似下面的东西,但它显然不起作用。 public class MyResponse { public List Settings { get; set;} } public class Setting { public int Cmd { get; set; } public int Status { get; set; } } 谢谢

使用JSON数组进行RestSharp反序列化

我有一个JSON响应,我正在尝试使用RestSharp反序列化 ,它看起来像这样: {“devices”:[{“device”:{“id”:7,”deviceid”:”abc123″,”name”:”Name”}}, {“device”:{“id”:1,”deviceid”:”def456″,”name”:”Name”}}], “total”:2, “start”:0, “count”:2} 根据我发现的一些建议,我试图像这样设置我的POCO: public class DevicesList { public List Devices; } public class DeviceContainer { public Device Device; } public class Device { public int Id { get; set; } public string DeviceId { get; set; } public string Name { get; set; } } 然后我的执行看起来像这样: // execute the request […]

在反序列化JSON响应时,RestSharp客户端将所有属性返回为null

我正在尝试使用RestSharp的Execute方法查询rest端点并序列化为POCO的一个非常简单的示例。 但是,我尝试的所有内容都会产生一个response.Data对象,该对象具有NULL值的所有属性。 这是JSON响应: { “Result”: { “Location”: { “BusinessUnit”: “BTA”, “BusinessUnitName”: “CASINO”, “LocationId”: “4070”, “LocationCode”: “ZBTA”, “LocationName”: “Name of Casino” } } } 这是我的测试代码 [TestMethod] public void TestLocationsGetById() { //given var request = new RestRequest(); request.Resource = serviceEndpoint + “/{singleItemTestId}”; request.Method = Method.GET; request.AddHeader(“accept”, Configuration.JSONContentType); request.RootElement = “Location”; request.AddParameter(“singleItemTestId”, singleItemTestId, ParameterType.UrlSegment); request.RequestFormat = DataFormat.Json; //when […]

如何使用Restsharp反序列化Xml列表?

我有这样的xml 1 1 1 0 2 1 2 0 … 我想将这个xml列表反序列化为POCO对象 public class Account { public string AccountId { get; set; } public string AccountTypeId { get; set; } public string AccountTypeName { get; set; } public string AccountBankId { get; set; } public string AccountBankName { get; set; } public string AccountSaldo { get; […]

RestSharp是否覆盖手动设置Content-Type?

我正在创建一个RestSharp.RestRequest: RestRequest request = new RestRequest(); request.Method = Method.POST; request.Resource = “/rest-uri”; request.AddHeader(“Content-Type”, “application/someContentType”); string xml = “” + Environment.NewLine + “” + Environment.NewLine + ” ” + Environment.NewLine + “”); request.AddParameter(“text/xml”, registerSinkRequest, ParameterType.RequestBody); (Content-Type手动设置为application/someContentType ) 在调试模式下,它还显示Content-Type=application/someContentType 但是执行RestRequest会返回415 Media Not Supported -Error并且WireShark显示Media-Type设置为text/xml (如AddParameter-Method中的set)。 为什么RestSharp显示与WireShark不同的Content-Type? 如何防止更改Content-Type(如果是)?

使用newtonsoft或restsharp反序列化json字符串

我有一个字符串,它来自一个Json格式的数据库。 我试图用以下方法反序列化它: RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer(); var x = deserial .Deserialize(myStringFromDB) 但.Deserialize函数需要一个IRestResponse 有没有办法使用RestSharp来反序列化原始字符串?

如何使用restsharp上传多个文件?

我想上传文件到这个api https://support.crowdin.com/api/add-file/ 如何使用RestSharp创建名为files的参数并向其添加多个文件? 我到目前为止编写了这段代码,但它不起作用,RestSharp似乎没有按预期上传文件。 var addUrl = new Uri($”https://api.crowdin.com/api/project/{projectIdentifier}/add-file?key={projectKey}&json=”); var restClient = new RestSharp.RestClient(“https://api.crowdin.com”); var request = new RestSharp.RestRequest($”api/project/{projectIdentifier}/add-file”, RestSharp.Method.POST); request.AlwaysMultipartFormData = true; request.AddQueryParameter(“key”, projectKey); request.AddQueryParameter(“json”, “”); var files = new Dictionary { { “testfile”, File.ReadAllBytes(fileName) } }; request.AddParameter(“files”, files, RestSharp.ParameterType.RequestBody); var restResponse = restClient.Execute(request); 这给了我 { “success”:false, “error”:{ “code”:4, “message”:”No files specified in request” […]

RestSharp发布一个JSON对象

我想用RestSharp发布以下JSON: {“UserName”:”UAT1206252627″, “SecurityQuestion”:{ “Id”:”Q03″, “Answer”:”Business”, “Hint”:”The answer is Business” }, } 我认为我很接近,但我似乎正在努力使用SecurityQuestion (API正在抛出一个错误,说参数丢失,但它没有说明哪一个) 这是我到目前为止的代码: var request = new RestRequest(“api/register”, Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter(“UserName”, “UAT1206252627”); SecurityQuestion securityQuestion = new SecurityQuestion(“Q03”); request.AddParameter(“SecurityQuestion”, request.JsonSerializer.Serialize(securityQuestion)); IRestResponse response = client.Execute(request); 我的安全问题类看起来像这样: public class SecurityQuestion { public string id {get; set;} public string answer {get; set;} public string hint {get; […]