restsharp

Retaining authorization header in RestSharp during redirects

戏子无情 提交于 2019-12-08 04:55:17
问题 I am using RestSharp to make a GET api call. The api call is authenticated through HTTP Basic authentication by passing the authorization header. The server redirects the api call with a status code 307. My client code does handle the redirects but the authorization header is not passed to this redirected api call. This is done for valid reasons as mentioned here. Hence I do get an unauthorized error. How can I configure the RestClient to restore the authorization header? var client = new

Upload to Onedrive with C# using Graph API

别来无恙 提交于 2019-12-08 04:20:01
问题 I am trying to upload a file to Onedrive using RestSharp and Graph API. Basically I want to upload an Excel file. However, even the file saves, there is problem with the content. I am using: https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_uploadcontent using the code: string newToken = "bearer ourtoken"; var client = new RestClient("https://xxx-my.sharepoint.com/_api/v2.0/"+ oneDrivePath + Path.GetFileName(filePathWithName) + ":/content"); var request = new RestRequest

RestSharp returns null value when response header has location field

心不动则不痛 提交于 2019-12-07 13:02:37
问题 My rest request: RestSharp.RestClient uplClient = new RestSharp.RestClient(); RestSharp.RestRequest request = new RestSharp.RestRequest(IMAGE_UPLOAD_URI, Method.POST); request.AddParameter("user", USER_HASH); request.AddParameter("apikey", API_KEY); request.AddFile("Filedata", file, "test.jpg","image/jpeg"); uplClient.ExecuteAsync(request, (response) => { callback(response.Content, null); if (response.StatusCode == HttpStatusCode.OK) { MessageBox.Show("Upload completed succesfully...\n" +

Deserialize nested JSON Response with RestSharp Client

巧了我就是萌 提交于 2019-12-07 12:56:23
问题 I'd like to consume a REST Api and deserialize the nested JSON Response. For that purpose I tried to create some POCO classes which represent the JSON Response [1]. The response looks like this: { "success": true, "message": "OK", "types": [ { "name": "A5EF3-ASR", "title": "ITIL Foundation Plus Cloud Introduction", "classroomDeliveryMethod": "Self-paced Virtual Class", "descriptions": { "EN": { "description": "some Text null", "overview": null, "abstract": "Some other text", "prerequisits":

Why is RestSharp deserializing two dates differently?

大城市里の小女人 提交于 2019-12-07 10:06:40
问题 I have a rest call that returns this (using Advance Rest Client in Chrome to do testing): MyObject: [22] 0: { ID: "123456" UTC1: "2013-04-19T03:12:32Z" UTC2: "2013-04-19T03:12:36.994Z" } The code that grabs the response and serializes it to an object looks like this: IRestResponse<List<MyObject>> response = client.Execute<List<MyObject>>(request); When I look at the response object one of the dates is wrong. If I inspect it or use the objects in any way I get this: UTC1: 4/19/2013 3:12 UTC2:

How to upload an XML file using multipart/form-data with Restsharp?

拥有回忆 提交于 2019-12-07 07:52:28
Question: How to upload an XML file using multipart/form-data with Restsharp? Problem: I'm using Peppol for sending invoices using the Codabox API. I want to upload an xml to the rest service. The rest service itself is under control by the provider Codabox. I have 2 methods provided who I expect to do the same. First of all with Postman and httpclient, all the things works fine. I want to get the same from the httpclient method working using the restsharp way. RestSharp version: 106.2.1 Error message with Restsharp response = "StatusCode: BadRequest, Content-Type: application/json, Content

Passing list of int to Web API from RestSharp Client

为君一笑 提交于 2019-12-07 05:23:54
问题 When I use code below from REST Sharp I am not able to pass listOfSelectedTicketsIds it always null. Request of Rest Sharp .net Client var _stDeveloperApi = new RestClient("http://127.0.0.1/"); var url = string.Format("api/v1/SignalR/MultiClickMode"); var listOfSelectedTicketsIds = new List<int> { 2, 3 }; var request = new RestRequest(url, Method.GET); request.AddParameter("listOfSelectedTicketsIds", listOfSelectedTicketsIds, ParameterType.GetOrPost); var response = _stDeveloperApi.Execute

Get value from RestSharp response headers

本秂侑毒 提交于 2019-12-07 00:18:19
问题 I'm hoping someone can help with an issue I'm having with RestSharp. It's all working; I'm getting my reply using the following code: var client = new RestClient("http://mybaseuri.com"); var request = new RestRequest("service/{id}", Method.GET); request.AddUrlSegment("id", id); // execute the request IRestResponse response = client.Execute(request); I'd like to get a value from the response headers along the lines of: string userId = response.Headers["userId"] I can't find any examples online

HttpStatus and DownloadData

守給你的承諾、 提交于 2019-12-06 20:39:00
问题 I'm trying to download a file (an image) with RestSharp using the DownloadData method var client = new RestClient(baseUrl); var request = new RestRequest("GetImage", Method.GET); var response = client.DownloadData(request); This works fine, but if the requests returns an error I cannot see the HttpStatus code. I could make a Request and check the status: var client = new RestClient(baseUrl); var request = new RestRequest("GetImage", Method.GET); var response = client.Execute(request); var

Rest Sharp Execute<Int> fails due to cast exception

廉价感情. 提交于 2019-12-06 16:30:39
I have this: public Int32 NumberOfLocationsForCompany(int companyId) { var response = _curl.ResetRequest() .WithPath(LOCATION_URL) .AddParam("companyId", companyId.ToString()) .RequestAsGet() .ProcessRequest<Int32>(); return response; } that calls this at the end. public T ProcessRequest<T>() where T : new() { var response = _client.Execute<T>(_request); if (response.ErrorException != null) { throw response.ErrorException; } return response.Data; } but I get this error. I don't get why it's trying to map an int to a collection or why it's Int64 vs the 32 I specified.: Unable to cast object of