本文整理汇总了C#中RestSharp.RestClient.GetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.GetAsync方法的具体用法?C# RestClient.GetAsync怎么用?C# RestClient.GetAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestClient
的用法示例。
在下文中一共展示了RestClient.GetAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetContentAsync
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;
}
示例2: DoRequest
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);
}
示例3: Get
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);
});
}
}
示例4: Authenticate
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;
}
);
}
示例5: HttpGetAsync
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);
});
}