當前位置: 首頁>>代碼示例>>C#>>正文


C# RestClient.GetAsync方法代碼示例

本文整理匯總了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;
        }
開發者ID:timschlechter,項目名稱:akka-demos,代碼行數:27,代碼來源:Webclient.cs

示例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);
        
    }
開發者ID:eamonwoortman,項目名稱:RestSharp.Unity.Tester,代碼行數:12,代碼來源:RestSharpTester.cs

示例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);
                                                                                             });
            }
        }
開發者ID:zsschoner,項目名稱:WebApiSample,代碼行數:15,代碼來源:RestSharpClient.cs

示例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;
                                      }
                );
        }
開發者ID:IngageNetworks,項目名稱:GhostWriter,代碼行數:19,代碼來源:API.cs

示例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);
     });
 }
開發者ID:zhang-xiao-ming,項目名稱:RestApiClient,代碼行數:11,代碼來源:UriExtensions.cs


注:本文中的RestSharp.RestClient.GetAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。