public Task<string> GetContentAsync(string url) { var tcs = new TaskCompletionSource<string>(); try { var client = new RestClient(url); client.GetAsync(new RestRequest(), (response, handle) => { if ((int)response.StatusCode >= 400) { tcs.SetException(new Exception(response.StatusDescription)); } else { tcs.SetResult(response.Content); } }); } catch (Exception ex) { tcs.SetException(ex); } return tcs.Task; }
public static void Get(string format) { var id = GetSelectedId(); if (id != Guid.Empty) { var c = new RestClient(String.Format("{0}/{1}?format={2}", baseUrl, id, format)); List<UserModel> res = Enumerable.Empty<UserModel>().ToList(); c.GetAsync<List<UserModel>>(CreateRequest(RestSharp.Method.GET, format), (resp, result) => { res = resp.Data; WriteResult("GET", resp); }); } }
public void Authenticate() { var request = new RestRequest("/", Method.GET) { RequestFormat = DataFormat.Json }; request.AddHeader("api-key", _apiKey); var stsClient = new RestClient(BaseSecureUrl) { Authenticator = new HttpBasicAuthenticator(_userName, _password) }; stsClient.GetAsync<Token>(request, (response, handle) => { if (response.StatusCode == HttpStatusCode.OK) if (response.Data != null) _accessToken = response.Data.AccessToken; else if (response.ErrorException != null) throw response.ErrorException; } ); }
public static void HttpGetAsync(this Uri uri, Action<IRestResponse> result) { if (uri == null) return; RestClient client = new RestClient(uri); RestRequest request = new RestRequest(); client.GetAsync(request, (restResponse, handle) => { result(restResponse); }); }
private void DoRequest(string requestUrl) { RestClient client = new RestClient(requestUrl); RestRequest request = new RestRequest("", Method.GET); request.AddHeader("test", "test"); Debug.Log("Testing url: " + requestUrl); IRestResponse response = client.Get(request); ValidateResponse(requestUrl, response, false); client.GetAsync(request, OnResponse); }