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


C# RestClient.SendAsync方法代码示例

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


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

示例1: InternalServerError500ReturnedWhenServerReturns500HttpStatus

        public async Task InternalServerError500ReturnedWhenServerReturns500HttpStatus()
        {
            // Setup
            var client = new RestClient { BaseUrl = BaseAddress };
            var request = new RestRequest("notsuccess/internalservererror");
            RestResponse<string> response;

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

            // Validate
            response.HttpResponseMessage.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
            response.Content.Should().BeNullOrEmpty();
        }
开发者ID:sahb1239,项目名称:PortableRest,代码行数:17,代码来源:SendAsyncTests.cs

示例2: DeleteShouldReturn204WithNoContent

        public async Task DeleteShouldReturn204WithNoContent()
        {
            // Setup
            var client = new RestClient { BaseUrl = BaseAddress };
            var request = new RestRequest("api/books", HttpMethod.Delete);
            RestResponse<string> response;

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

            // Validate
            response.HttpResponseMessage.StatusCode.Should().Be(HttpStatusCode.NoContent);
            response.Content.Should().BeNull();
        }
开发者ID:sahb1239,项目名称:PortableRest,代码行数:17,代码来源:SendAsyncTests.cs

示例3: NotFound404ReturnedWhenServerReturnsNotFoundHttpStatus

        public async Task NotFound404ReturnedWhenServerReturnsNotFoundHttpStatus()
        {
            // Setup
            var client = new RestClient{ BaseUrl = BaseAddress };
            var request = new RestRequest("notsuccess/notfound");
            RestResponse<string> response;

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

            // Validate
            response.HttpResponseMessage.StatusCode.Should().Be(HttpStatusCode.NotFound);
            response.Content.Should().BeNull();
        }
开发者ID:jeffijoe,项目名称:PortableRest,代码行数:17,代码来源:SendAsyncTests.cs

示例4: GracefullyHandleNullContentWithNonStringType

        public async Task GracefullyHandleNullContentWithNonStringType()
        {
            // Setup
            var client = new RestClient { BaseUrl = BaseAddress };
            var request = new RestRequest("notsuccess/notfound");
            RestResponse<IEnumerable<Book>> response;


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


            // Validate
            response.HttpResponseMessage.StatusCode.Should().Be(HttpStatusCode.NotFound);
            response.Content.Should().BeNull();
        }
开发者ID:sahb1239,项目名称:PortableRest,代码行数:19,代码来源:SendAsyncTests.cs

示例5: SendAsyncOfTContainsHttpResponseAndDeserializedContent

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

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

            // Validate
            response.HttpResponseMessage.Should().NotBeNull();
            response.HttpResponseMessage.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Should().NotBeNull();
            response.Content.Count().Should().Be(5);
        }
开发者ID:sahb1239,项目名称:PortableRest,代码行数:19,代码来源:SendAsyncTests.cs

示例6: JsonDeserializerSettingsAreUsedWhenDeserializingJson

        public void JsonDeserializerSettingsAreUsedWhenDeserializingJson()
        {
            // Setup
            var settings = new JsonSerializerSettings();
            var converterMock = new JsonConverterMock();
            settings.Converters.Add(converterMock);
            var client = new RestClient { BaseUrl = BaseAddress, JsonSerializerSettings = settings };
            var request = new RestRequest("api/books");
            RestResponse<List<Book>> response = null;

            // Execute
            using (WebApp.Start<WebApiStartup>(BaseAddress))
            {
                // Simulate ASP.NET and Windows Forms thread affinity
                WindowsFormsContext.Run(() =>
                {
                    // Should not deadlock on this call
                    response = client.SendAsync<List<Book>>(request).Result;
                });
            }

            // Validate
            converterMock.Calls.Should().NotBe(0);
            response.Content.Should().NotBeNull();
            response.Content.Count().Should().Be(5);

        }
开发者ID:sahb1239,项目名称:PortableRest,代码行数:27,代码来源:SendAsyncTests.cs

示例7: AsyncLibrariesLikePortableRestShouldNotDeadlockOnTaskResult

        public void AsyncLibrariesLikePortableRestShouldNotDeadlockOnTaskResult()
        {
            // Setup
            var client = new RestClient { BaseUrl = BaseAddress };
            var request = new RestRequest("api/books");
            RestResponse<List<Book>> response = null;

            // Execute
            using (WebApp.Start<WebApiStartup>(BaseAddress))
            {
                // Simulate ASP.NET and Windows Forms thread affinity
                WindowsFormsContext.Run(() =>
                {
                    // Should not deadlock on this call
                    response = client.SendAsync<List<Book>>(request).Result;
                });
            }

            // Validate
            Assert.IsTrue(true, "If we got to this assertion, then we didn't deadlock on the call to SendAsync.");
            response.Content.Should().NotBeNull();
            response.Content.Count().Should().Be(5);

        }
开发者ID:sahb1239,项目名称:PortableRest,代码行数:24,代码来源:SendAsyncTests.cs

示例8: TestWS_Tapped

        private async void TestWS_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            int i = 0;
            String sessionId = "zM4DQxmA7ad3OsLUFYdBTHmC69m96ilFTGazusy5";
            RestClient rc = new RestClient()
            {
                BaseUrl = "http://10.37.129.2:8080"
            };
            RestRequest req = null;
            RestResponse<String> ret = null;

            req = new RestRequest()
            {
                ContentType= ContentTypes.FormUrlEncoded,
                Method = HttpMethod.Post,
                Resource = "api/authentication"
            };
            req.AddParameter("j_username", "admin");
            req.AddParameter("j_password", "admin");
            //req.AddParameter("submit", "Login");
            ret = await rc.SendAsync<string>(req);
            i++;

            //req = new RestRequest() {
            //    //ContentType= ContentTypes.FormUrlEncoded,
            //    Method = HttpMethod.Get,
            //    Resource = "authenticate"
            //};

            //req.AddParameter("j_username", "admin");
            //req.AddParameter("j_password", "admin");
            ////req.AddParameter("remember-me", "true");
            ////req.AddParameter("submit", "Login");

            //req.AddParameter("Authorization", "Basic YWRtaW46YWRtaW4=");

            ////req.AddQueryString("j_username", "admin");
            ////req.AddQueryString("j_password", "admin");
            ////req.AddQueryString("remember-me", "true");
            ////req.AddQueryString("submit", "Login");

            //ret = await rc.SendAsync<string>(req);

            //foreach (String cookie in ret.HttpResponseMessage.Headers.GetValues("Set-Cookie"))
            //{
            //    if (cookie.StartsWith("JSESSIONID="))
            //    {
            //        sessionId = cookie.Split(';')[0].Split('=')[1];
            //    }
            //}



            req = new RestRequest()
            {
                //ContentType = ContentTypes.FormUrlEncoded,
                Method = HttpMethod.Get,
                //Resource = "authenticate"
                Resource = "/api/events/owned"
            };
            //req.AddHeader("Cookie", "JSESSIONID="+sessionId);
            //req.AddHeader("Accept", "application/json");
            //req.AddParameter("JSESSIONID", sessionId);
            //req.AddQueryString("JSESSIONID", sessionId);

            RestResponse<List<EventDTO>> ret2 = await rc.SendAsync<List<EventDTO>>(req);
            
            i++;
            /*
            var client = new RestClient("http://example.com");
            // client.Authenticator = new HttpBasicAuthenticator(username, password);

            var request = new RestRequest("resource/{id}", Method.POST);
            request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
            request.AddUrlSegment("id", "123"); // replaces matching token in request.Resource

            // easily add HTTP Headers
            request.AddHeader("header", "value");
            */
        }
开发者ID:ArnaudLorenzi,项目名称:EventApp,代码行数:80,代码来源:Page1.xaml.cs

示例9: SettingAcceptsHeaderOnGetDoesntThrow

        public async Task SettingAcceptsHeaderOnGetDoesntThrow()
        {
            // Setup
            var client = new RestClient { BaseUrl = BaseAddress };
            var request = new RestRequest("api/books");
            request.AddHeader("Content-Type", "application/json");
            RestResponse<IEnumerable<Book>> response;

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

            // Validate
            response.HttpResponseMessage.Should().NotBeNull();
            response.HttpResponseMessage.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Should().NotBeNull();
            response.Content.Count().Should().Be(5);
        }
开发者ID:advancedrei,项目名称:PortableRest,代码行数:20,代码来源:SendAsyncTests.cs


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