restsharp

Serializing an object with restsharp and passing it to WebApi not serializing list

孤人 提交于 2019-12-03 16:50:17
问题 I have a a view model that looks like. public class StoreItemViewModel { public Guid ItemId { get; set; } public List<Guid> StoreIds { get; set; } [Required] public string Description { get; set; } //[Required] //[DataMember(IsRequired = true)] public int ItemTypeId { get; set; } } I have a small helper that using is using RestSharp. public static IRestResponse Create<T>(object objectToUpdate, string apiEndPoint) where T : new() { var client = new RestClient(CreateBaseUrl(null)) {

Web Request through Proxy using RestSharp

左心房为你撑大大i 提交于 2019-12-03 16:49:15
问题 I'm trying to make a webrequest through a proxy on Windows phone 7. From what I can see the Compact Framework does not include the configuring of a proxy for the HttpWebRequest object. I tried using RestSharp but the RestClient also does not allow this. I've also tried configuring the Internet Options on my local machine to use a proxy, hopping that the same options will apply on my Windows Phone Emulator. That didn't work. Do you have any ideas? 回答1: Under "configuration" section in Web

In C#, how do I model a JSON object with multiple nested arrays?

别等时光非礼了梦想. 提交于 2019-12-03 14:21:36
I am getting this JSON response from a system I am connecting to and trying to figure out the best way to deserialize it into a C# object. I am currently using RestSharp which seems pretty straight forward to use but the format of the JSON is baffling me a bit. Here is the format that its coming in as: [ {"name": "Tickets:", "schema": [ {"dataType": "string", "colName": "First", "idx": 0}, {"dataType": "string", "colName": "Second", "idx": 1}, {"dataType": "string", "colName": "Name", "idx": 2} ], "data": [ ["bill", "test", "joe"], ["bill2", "test2", "joe2"], ["bill3", "test3", "joe3"] ] } ]

How to mock RestSharp portable library in Unit Test

大憨熊 提交于 2019-12-03 13:51:30
问题 I would like to mockup the RestClient class for test purposes public class DataServices : IDataServices { private readonly IRestClient _restClient; public DataServices(IRestClient restClient) { _restClient = restClient; } public async Task<User> GetUserByUserName(string userName) { User user = null; // create a new request var restRequest = new RestRequest("User", Method.GET); // create REST parameters restRequest.AddParameter("userName", userName, ParameterType.QueryString); // execute the

RestSharp - Authorization Header not coming across to WCF REST service

与世无争的帅哥 提交于 2019-12-03 11:19:17
问题 I am trying to call a locally hosted WCF REST service over HTTPS with basic auth. This works and the Authorization header comes thru just fine and all is happy: ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertficate; var request = (HttpWebRequest)WebRequest.Create("https://localhost/MyService/MyService.svc/"); request.Method = "GET"; request.ContentType = "application/json"; request.Headers.Add( System.Net.HttpRequestHeader.Authorization, "Basic " + this

How do I install and setup RESTSharp without NuGet?

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using Visual Studio C# 2010 Express and is learning. RESTSharp is supposed to be installed by NuGet but NuGet cannot be used with Express version. Can I still install and configure RESTSharp manually, and how? 回答1: The NuGet Visual Studio plugin can't be used with Express, but you can install NuGet packages from the command line . You'll need to download the command line bootstrapper from the NuGet CodePlex site . After installing it, you can just use nuget Install SomePackageName and it will fetch the package and its

Serializing an object with restsharp and passing it to WebApi not serializing list

你离开我真会死。 提交于 2019-12-03 05:48:51
I have a a view model that looks like. public class StoreItemViewModel { public Guid ItemId { get; set; } public List<Guid> StoreIds { get; set; } [Required] public string Description { get; set; } //[Required] //[DataMember(IsRequired = true)] public int ItemTypeId { get; set; } } I have a small helper that using is using RestSharp. public static IRestResponse Create<T>(object objectToUpdate, string apiEndPoint) where T : new() { var client = new RestClient(CreateBaseUrl(null)) { Authenticator = new HttpBasicAuthenticator("user", "Password1") }; var request = new RestRequest(apiEndPoint,

How to use OAuth2 in RestSharp

霸气de小男生 提交于 2019-12-03 04:14:22
问题 After a couple of days sorting out OAuth2 at the server-end (Spring java) I started working on the client written in C#. I am using RestSharp to call my web API but I am having real difficulty with the OAuth2. There is hardly any documentation and the few examples I found online do not work. Can someone provide me a code sample that is up to date and that I can use? So far I have the following: var client = new RestClient("http://example.com/myapi/oauth/token"); RestRequest request = new

Add a GET parameter to a POST request with RestSharp

与世无争的帅哥 提交于 2019-12-03 01:51:54
I want to make a POST request to a URL like this: http://localhost/resource?auth_token=1234 And I want to send JSON in the body. My code looks something like this: var client = new RestClient("http://localhost"); var request = new RestRequest("resource", Method.POST); request.AddParameter("auth_token", "1234"); request.AddBody(json); var response = client.Execute(request); How can I set the auth_token parameter to be a GET parameter and make the request as POST? This should work if you 1) add the token to the resource url and 2) specify ParameterType.UrlSegment like this: var client = new

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

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to RestSharp add client certificate in Https request ? My code it doesn't work . 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(