restsharp

Sending HTTP POST Multipart/form-data field using RestSharp

为君一笑 提交于 2019-12-17 18:36:36
问题 I'm having issues using RestSharp for a REST API I need to use for a project I'm working on. The request I need to issue is in three parts: A header API key, a file to upload, and a bunch of data in JSON format. The API requires that the data part be sent using a form field name of "data". For some reason this is causing issues since it's naming the field "data" within the body of the request. The code I have as is as follows: var request = new RestRequest(UPLOAD_DOC_URLSEGMENT, Method.POST)

How should I implement ExecuteAsync with RestSharp on Windows Phone 7?

无人久伴 提交于 2019-12-17 17:48:16
问题 I'm attempting to use the documentation on the RestSharp GitHub wiki to implement calls to my REST API service but I'm having an issue with the ExecuteAsync method in particular. Currently my code looks like this for the API class: public class HarooApi { const string BaseUrl = "https://domain.here"; readonly string _accountSid; readonly string _secretKey; public HarooApi(string accountSid, string secretKey) { _accountSid = accountSid; _secretKey = secretKey; } public T Execute<T>(RestRequest

Moving from standard .NET rest to RestSharp

∥☆過路亽.° 提交于 2019-12-14 03:57:27
问题 For the most part, I have managed quite quickly to move my code from standard .NET code to using RestSharp. This has been simple enough for GET processes, but I'm stumped for POST processes Consider the following var request = System.Net.WebRequest.Create("https://mytestserver.com/api/usr") as System.Net.HttpWebRequest; request.Method = "POST"; request.ContentType = "application/json;version=1"; request.Headers.Add("Content-Type", "application/json;version=1"); request.Headers.Add("Accepts",

How to use HubUpload Post api?

我是研究僧i 提交于 2019-12-13 22:47:41
问题 im looking at api opened by Microsoft Translator Hub (Microsoft Translator Hub Api Swagger Link) and i cant figure out how to use the upload file part. The other operation ive managed to do but i cant figure out how to use the HubUpload operation. For HubUpload/Get public void GetStatusHubUpload(string accessToken) { var client = new RestClient("https://hub.microsofttranslator.com/api/HubUpload/Get"); var request = new RestRequest(Method.GET); request.AddParameter("trackingId", /*Integer*/);/

RestSharp deserialization containing both a value and a dictionary under the root element

你说的曾经没有我的故事 提交于 2019-12-13 21:17:00
问题 I am trying to construct POCO classes so that RestSharp can deserialize a particular JSON result. The sticking point seems to be that the root object contains both a nb_results key, and a dictionary of other keys ("0:", "1:", etc. each with a complex value). I have tried both Dictionary(Of Integer, mediaGalleryData) and Dictionary(Of String, mediaGalleryData). Neither works. nb_results always serializes, but the dictionary never does. { "nb_results": 2, "0": { "id": 51976254, "title":

how to deserialize xml to list in RestSharp?

梦想的初衷 提交于 2019-12-13 17:25:16
问题 My XML: <result> <document version="2.1.0"> <response type="currency"> <currency> <code>AMD</code> <price>85.1366</price> </currency> </response> <response type="currency"> <currency> <code>AUD</code> <price>31.1207</price> </currency> </response> </document> </result> My Class: public class CurrencyData { public string Code { get; set; } public string Price { get; set; } } My deserializer calling: RestClient.ExecuteAsync<List<CurrencyData>>... If i renamed class CurrencyData to Currency then

ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#

本秂侑毒 提交于 2019-12-13 16:38:07
问题 I'm new to C#, RestSharp, and threading, so heres what I'm trying to do: I have made a program that will allow me to upload photos to tumblr, and I have the uploading working so far. Now I need the stop button to work, which I believe means I must use ExecuteAsync() instead of Execute() . I also have my code put in a backgroundworker, like this: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if (backgroundWorker1.CancellationPending) { e.Cancel = true; MessageBox

Equivalent of Python's request.session.auth in C# (.NET)

我的未来我决定 提交于 2019-12-13 15:58:50
问题 In Python I can successfully make a request (with authorization passing) by doing: def send_request(self, url, public_key, secret_key): session = requests.session() session.auth = (public_key, secret_key) return session.get(url) I'm trying to replicate this in C# but it's not authorizing: RestClient client = new RestClient(url); RestRequest request = new RestRequest(url_stuff, Method.GET); request.AddHeader(public_key, secret_key); return client.Execute(request).Content; What am I missing

How to handle return values in async function

倖福魔咒の 提交于 2019-12-13 12:34:16
问题 When working on data APIs which use async rest calls (I am using RestSharp.Portable), what is the best way to handle return values? Since async function can only return a Task or Task ... but the caller has no way to getting back to the return value ... how would the API return data back to the caller? Global properties? From what I have read so far, it appears that callback functions are the only way to interact with Response Data? Take the following method for example; previously I was not

RestSharp send Dictionary

為{幸葍}努か 提交于 2019-12-13 05:57:03
问题 I've seen how to deserialize a dictionary from the response, but how do you send one? var d = new Dictionary<string, object> { { "foo", "bar" }, { "bar", 12345 }, { "jello", new { qux = "fuum", lorem = "ipsum" } } }; var r = new RestRequest(url, method); r.AddBody(d); // <-- how? var response = new RestClient(baseurl).Execute(r); 回答1: Ugh...it was something else screwing up my case. As @Chase said, it's pretty simple: var c = new RestClient(baseurl); var r = new RestRequest(url, Method.POST);