本文整理匯總了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);
});
}