当前位置: 首页>>代码示例>>C#>>正文


C# RestClient.ExecuteAsync方法代码示例

本文整理汇总了C#中RestClient.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.ExecuteAsync方法的具体用法?C# RestClient.ExecuteAsync怎么用?C# RestClient.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestClient的用法示例。


在下文中一共展示了RestClient.ExecuteAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MultipleRequestsFromSameClientShouldNotFail

        public async Task MultipleRequestsFromSameClientShouldNotFail()
        {
            // Setup
            var client = new RestClient { BaseUrl = BaseAddress };
            var request = new RestRequest("api/books");
            List<Book> response;

            // Execute
            using (WebApp.Start<WebApiStartup>(BaseAddress))
            {
                response = await client.ExecuteAsync<List<Book>>(request);
            }

            // Validate
            response.Should().NotBeNull();
            response.Count().Should().Be(5);

            var request2 = new RestRequest("api/books");
            List<Book> response2;

            // Execute
            using (WebApp.Start<WebApiStartup>(BaseAddress))
            {
                response2 = await client.ExecuteAsync<List<Book>>(request2);
            }

            // Validate
            response2.Should().NotBeNull();
            response2.Count().Should().Be(5);
        }
开发者ID:westwok,项目名称:PortableRest,代码行数:30,代码来源:ExecuteAsyncTests.cs

示例2: Handles_Server_Timeout_Error_Async

        public void Handles_Server_Timeout_Error_Async()
        {
            const string baseUrl = "http://localhost:8888/";
            var resetEvent = new ManualResetEvent(false);

            using (SimpleServer.Create(baseUrl, TimeoutHandler))
            {
                var client = new RestClient(baseUrl);
                var request = new RestRequest("404") { Timeout = 500 };
                IRestResponse response = null;

                client.ExecuteAsync(request, responseCb =>
                                             {
                                                 response = responseCb;
                                                 resetEvent.Set();
                                             });

                resetEvent.WaitOne();

                Assert.NotNull(response);
                Assert.Equal(response.ResponseStatus, ResponseStatus.TimedOut);
                Assert.NotNull(response.ErrorException);
                Assert.IsAssignableFrom(typeof(WebException), response.ErrorException);
                Assert.Equal(response.ErrorException.Message, "The request timed-out.");
            }
        }
开发者ID:mgulubov,项目名称:RestSharpHighQualityCodeTeamProject,代码行数:26,代码来源:NonProtocolExceptionHandlingTests.cs

示例3: Can_Perform_GET_Async

        public void Can_Perform_GET_Async()
        {
            const string baseUrl = "http://localhost:8084/";
            const string val = "Basic async test";

            var resetEvent = new ManualResetEvent(false);

            using (SimpleServer.Create(baseUrl, Handlers.EchoValue(val)))
            {
                var client = new RestClient(baseUrl);
                var request = new RestRequest("");
                IRestResponse response = null;

                client.ExecuteAsync(request, (resp, asyncHandle) =>
                {
                    response = resp;
                    resetEvent.Set();
                });

                resetEvent.WaitOne();

                Assert.NotNull(response.Content);
                Assert.Equal(val, response.Content);
            }
        }
开发者ID:danielbcorreia,项目名称:RestSharp,代码行数:25,代码来源:AsyncTests.cs

示例4: Authenticate

        private async Task Authenticate()
        {
            var client = new RestClient
            {
                BaseUrl = "https://datamarket.accesscontrol.windows.net",
                UserAgent = UserAgent,
            };
            var request = new RestRequest("v2/OAuth2-13", HttpMethod.Post)
            {
                ContentType = ContentTypes.FormUrlEncoded,
                ReturnRawString = true,
            };
            request.AddParameter("client_id", ClientId);
            request.AddParameter("client_secret", ClientSecret);
            request.AddParameter("scope", "http://music.xboxlive.com");
            request.AddParameter("grant_type", "client_credentials");

            var result = await client.ExecuteAsync<string>(request);

            TokenResponse = JsonConvert.DeserializeObject<TokenResult>(result);
            if (TokenResponse != null)
            {
                TokenResponse.TimeStamp = DateTime.Now;
            }
        }
开发者ID:rwecho,项目名称:Windows-Phone-Samples,代码行数:25,代码来源:XboxMusic.cs

示例5: GetResourceAsync

        public async Task<byte[]> GetResourceAsync(Uri uri)
        {
            var client = new RestClient();
            var request = new RestRequest(uri.AbsoluteUri, HttpMethod.Get, ContentTypes.ByteArray);

            var result = await client.ExecuteAsync<byte[]>(request);

            return result;
        }
开发者ID:FasinThundes,项目名称:HearthstoneApi,代码行数:9,代码来源:PortableRestClient.cs

示例6: Can_Handle_Uncompressed_Content

		public async Task Can_Handle_Uncompressed_Content()
		{
			const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => Handlers.EchoValue(request.Path) ))
			{
				var client = new RestClient(baseUrl);
				var request = new RestRequest("uncompressed.json.txt");
				var response = await client.ExecuteAsync(request);

                Assert.AreEqual("This is some sample content", response.Content);
			}
		}
开发者ID:RestRT,项目名称:RestRT,代码行数:12,代码来源:CompressionTests.cs

示例7: Handles_GET_Request_404_Error

        public async Task Handles_GET_Request_404_Error()
        {
            const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => UrlToStatusCodeHandler(request.Path) ))
            {
                var client = new RestClient(baseUrl);
                var request = new RestRequest("404");
                var response = await client.ExecuteAsync(request);

                Assert.AreEqual((int)HttpStatusCode.NotFound, response.StatusCode);
            }
        }
开发者ID:RestRT,项目名称:RestRT,代码行数:12,代码来源:StatusCodeTests.cs

示例8: Can_Authenticate_With_Basic_Http_Auth

		public async Task Can_Authenticate_With_Basic_Http_Auth()
		{
			const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => UsernamePasswordEchoHandler(request) ))
			{
				var client = new RestClient(baseUrl);
				client.Authenticator = new HttpBasicAuthenticator("testuser", "testpassword");

				var request = new RestRequest("basicAuth.json.txt");
				var response = await client.ExecuteAsync(request);

				Assert.AreEqual("testuser|testpassword", response.Content);
			}
		}
开发者ID:RestRT,项目名称:RestRT,代码行数:14,代码来源:AuthenticationTests.cs

示例9: Can_Handle_Deflate_Compressed_Content

		public async Task Can_Handle_Deflate_Compressed_Content()
		{
			const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => DeflateEchoValue(request.Path)))
			{
				var client = new RestClient(baseUrl);
				var request = new RestRequest("deflate.json.txt");
				var response = await client.ExecuteAsync(request);

                System.Diagnostics.Debug.WriteLine("CONTENT: " + response.Content);

                Assert.AreEqual("This is some deflated content", response.Content);
			}
		}
开发者ID:RestRT,项目名称:RestRT,代码行数:14,代码来源:CompressionTests.cs

示例10: MultipartFormDataAsync

 public void MultipartFormDataAsync()
 {
     const string baseUrl = "http://localhost:8080/";
     using (SimpleServer.Create(baseUrl, EchoHandler)) {
         var client = new RestClient(baseUrl);
         var request = new RestRequest("/");
         request.Method = Method.POST;
         request.AlwaysMultipartFormData = true;
         AddParameters(request);
         var restRequestAsyncHandle = client.ExecuteAsync(request, (restResponse, handle) => {
             Console.WriteLine(restResponse.Content);
             Assert.True(restResponse.Content == Expected);
         });
     }
 }
开发者ID:Bug2014,项目名称:RestSharp,代码行数:15,代码来源:MultipartFormDataTests.cs

示例11: TestMethod1

        public void TestMethod1()
        {
            //var client = new RestClient("https://api.twilio.com");
            //client.Authenticator = new HttpBasicAuthenticator("ACec243f00aaaa1b67fa32ae88178ebc2c", "09772adb6b86ba9341168d5277d18fb2");

            //var request = new RestRequest("2010-10-01/Accounts/ACec243f00aaaa1b67fa32ae88178ebc2c");

            var client = new RestClient("http://bing.com");

            var request = new RestRequest();

            client.ExecuteAsync(request, r => {
                Debug.WriteLine(r.Content);
            });
        }
开发者ID:stgwilli,项目名称:RestSharp,代码行数:15,代码来源:Tests.cs

示例12: Can_Have_No_Body_Added_To_POST_Request

        public void Can_Have_No_Body_Added_To_POST_Request()
        {
            const Method httpMethod = Method.POST;

            using (SimpleServer.Create(BASE_URL, Handlers.Generic<RequestBodyCapturer>()))
            {
                RestClient client = new RestClient(BASE_URL);
                RestRequest request = new RestRequest(RequestBodyCapturer.RESOURCE, httpMethod);
                ManualResetEvent resetEvent = new ManualResetEvent(false);

                client.ExecuteAsync(request, response => resetEvent.Set());
                resetEvent.WaitOne();

                AssertHasNoRequestBody();
            }
        }
开发者ID:CL0SeY,项目名称:RestSharp,代码行数:16,代码来源:AsyncRequestBodyTests.cs

示例13: Can_Perform_GET_Async

		public async Task Can_Perform_GET_Async()
		{
			const string baseUrl = "http://localhost:8080/";
			const string val = "Basic async test";
			var resetEvent = new ManualResetEvent(false);
			//using (SimpleServer.Create(baseUrl, Handlers.EchoValue(val)))
            using (HttpServer server = new HttpServer(8080, request => Handlers.EchoValue(request.Path)))
			{
				var client = new RestClient(baseUrl);
				var request = new RestRequest("");

                var response = await client.ExecuteAsync(request);
                
                Assert.IsNotNull(response.Content);
                Assert.AreEqual(val, response.Content);
			}
		}
开发者ID:RestRT,项目名称:RestRT,代码行数:17,代码来源:AsyncTests.cs

示例14: ExecuteAsyncOfTReturnsDeserializedContentOfT

        public async Task ExecuteAsyncOfTReturnsDeserializedContentOfT()
        {
            // Setup
            var client = new RestClient { BaseUrl = BaseAddress };
            var request = new RestRequest("api/books");
            List<Book> response;

            // Execute
            using (WebApp.Start<WebApiStartup>(BaseAddress))
            {
                response = await client.ExecuteAsync<List<Book>>(request);
            }

            // Validate
            response.Should().NotBeNull();
            response.Count().Should().Be(5);
        }
开发者ID:westwok,项目名称:PortableRest,代码行数:17,代码来源:ExecuteAsyncTests.cs

示例15: MultipartFormDataAsync

        public void MultipartFormDataAsync()
        {
            const string BaseUrl = "http://localhost:8888/";

            using (SimpleServer.Create(BaseUrl, EchoHandler))
            {
                var client = new RestClient(BaseUrl);
                var request = new RestRequest("/", Method.POST) { AlwaysMultipartFormData = true };

                this.AddParameters(request);

                client.ExecuteAsync(request, (restResponse, handle) =>
                {
                    Console.WriteLine(restResponse.Content);
                    Assert.Equal(this.expected, restResponse.Content);
                });
            }
        }
开发者ID:mgulubov,项目名称:RestSharpHighQualityCodeTeamProject,代码行数:18,代码来源:MultipartFormDataTests.cs


注:本文中的RestClient.ExecuteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。