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


C# HttpClient.FollowLinkAsync方法代码示例

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


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

示例1: Returns_content_if_response_is_OK

        public async Task Returns_content_if_response_is_OK()
        {
            string content = Guid.NewGuid().ToString();
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StringContent(content);

            var httpClient = new HttpClient(new FakeHandler
            {
                Response = response,
                InnerHandler = new HttpClientHandler()
            });

            var link = new GuidServiceLink();
            Guid guid = Guid.Empty;
            var machine = new HttpResponseMachine();
            machine.AddResponseHandler(async (lr, r) =>
            {
                {
                    
                    guid = Guid.Parse( r.Content.ReadAsStringAsync().Result);
                    return r;
                }
            }, HttpStatusCode.OK);


            await httpClient.FollowLinkAsync(link,machine);
            
            Assert.Equal(content, guid.ToString());



        }
开发者ID:tavis-software,项目名称:Tavis.Link,代码行数:32,代码来源:GuidServiceLinkTest.cs

示例2: SpecifyHandlerChainForAboutLink

        public Task SpecifyHandlerChainForAboutLink()
        {
            var foo = false;
            var bar = false;
            var baz = false;
  
            var registry = new LinkFactory();
            var grh = new InlineResponseHandler((rel,hrm) => baz = true,
                new InlineResponseHandler((rel, hrm) => foo = true,
                    new InlineResponseHandler((rel, hrm) => bar = true)));

            var machine = new HttpResponseMachine();
            machine.AddResponseHandler(grh.HandleResponseAsync, System.Net.HttpStatusCode.OK);
            

            var link = registry.CreateLink<AboutLink>();
            link.Target = new Uri("http://example.org");
            var httpClient = new HttpClient(new FakeHandler() { Response = new HttpResponseMessage()});

            return httpClient.FollowLinkAsync(link,machine).ContinueWith(t =>
                {
                    Assert.True(foo);
                    Assert.True(bar);
                    Assert.True(baz);
                });

        }
开发者ID:tavis-software,项目名称:Tavis.Link,代码行数:27,代码来源:LinkRegistryTests.cs

示例3: TestLink

 public void TestLink()
 {
     var link = new GuidServiceLink()
         {
             Target = new Uri("http://localhost/guidservice")
         };
     var httpClient = new HttpClient();
     httpClient.FollowLinkAsync(link);
     
 }
开发者ID:tavis-software,项目名称:Tavis.Link,代码行数:10,代码来源:GuidServiceLinkTest.cs

示例4: Test

        public Task Test()
        {
            var link = new Link(){Target = new Uri("http://localhost")};

            link.HttpResponseHandler = new NotFoundHandler(new OkHandler(null));

            var client = new HttpClient(new FakeHandler() {Response = new HttpResponseMessage() {StatusCode = HttpStatusCode.NotFound}});

            return client.FollowLinkAsync(link);
        }
开发者ID:rollingthunder,项目名称:Link,代码行数:10,代码来源:ResponseHandlerTests.cs

示例5: Test

        public async Task Test()
        {
            var link = new Link(){Target = new Uri("http://localhost")};

            var notFoundHandler = new NotFoundHandler(new OkHandler(null));
            var machine = new HttpResponseMachine();
            machine.AddResponseHandler(notFoundHandler.HandleResponseAsync, HttpStatusCode.NotFound);

            var client = new HttpClient(new FakeHandler() {Response = new HttpResponseMessage() {StatusCode = HttpStatusCode.NotFound}});

            await client.FollowLinkAsync(link,machine);

            Assert.True(notFoundHandler.NotFound);
        }
开发者ID:tavis-software,项目名称:Tavis.Link,代码行数:14,代码来源:ResponseHandlerTests.cs

示例6: FollowAndApplyInDistinctSteps

        public async Task FollowAndApplyInDistinctSteps()
        {
            var link = new Link() {Target = new Uri("http://example.org/")};

            var client = new HttpClient(new FakeHandler() { Response = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.NotFound
            } });
            
            var clientState = new ClientApplicationState();

            await client.FollowLinkAsync(link)
                        .ApplyRepresentationToAsync(clientState);

            Assert.Equal(HttpStatusCode.NotFound, clientState.StatusCode);
        }
开发者ID:tavis-software,项目名称:Tavis.Link,代码行数:16,代码来源:ResponseHandlerTests.cs

示例7: Throws_exception_if_response_not_OK

        public void Throws_exception_if_response_not_OK()
        {
            var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
            var httpClient = new HttpClient(new FakeHandler
            {
                Response = response,
                InnerHandler = new HttpClientHandler()
            });
              var machine = new HttpResponseMachine();
              machine.AddResponseHandler((l, r) => { throw new Exception(); }, HttpStatusCode.BadRequest); 

            var task = httpClient.FollowLinkAsync(new GuidServiceLink(),machine);
            
            Assert.Throws<AggregateException>(() => task.Wait());
            
        }
开发者ID:tavis-software,项目名称:Tavis.Link,代码行数:16,代码来源:GuidServiceLinkTest.cs

示例8: CodeSearchUsingLink

        private static async Task CodeSearchUsingLink()
        {
            var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders
                .UserAgent.Add(new ProductInfoHeaderValue("DarrelsGitClient", "1.0"));

            // API Specific type acts as Request Factory
            var codeSearchLink = new CodeSearchLink()
            {
                Template = new UriTemplate("https://api.github.com/search/code?q={query}{&page,per_page,sort_order}"),
                Query = ".Result user:darrelmiller"
            };

            var requestMessage = codeSearchLink.CreateRequest();
           
            var responseMessage = await httpClient.SendAsync(requestMessage);
            
            // ReadAs extension takes advantage of media type defined by API
            var githubdoc = await responseMessage.Content.ReadAsGithubDocumentAsync();

            // API Specific Link Type knows how to interpret generic media type
            var searchResults = CodeSearchLink.InterpretMessageBody(githubdoc);

            foreach (var result in searchResults.Items)
            {
                Console.WriteLine(result.Path);
            }

            // Harvest strongly typed links from strongly typed searchresults
            var fileLinks = searchResults.Items
                .Where(i => i.Name.Contains("Slack") && i.CodeFileLink != null)
                .Select(i => i.CodeFileLink);

            foreach (var fileLink in fileLinks)
            {
                // Following Links is a way of navigating the API's object graph
                var fileResponse = await httpClient.FollowLinkAsync(fileLink);

                // Reuse media type parser
                var fileDoc = await fileResponse.Content.ReadAsGithubDocumentAsync();

                // Use Type Specific Link to interpret results
                var codeFile = CodeFileLink.InterpretMessageBody(fileDoc);
                Console.WriteLine(codeFile.Content);
            }
        }  
开发者ID:hapikit,项目名称:github.net.hapikit,代码行数:46,代码来源:Program.cs

示例9: SpecifyHandlerChainForAboutLink

        public Task SpecifyHandlerChainForAboutLink()
        {
            var foo = false;
            var bar = false;
            var baz = false;

            var registry = new LinkFactory();
            var grh = new ActionResponseHandler((hrm) => baz = true,
                new ActionResponseHandler((hrm) => foo = true,
                    new ActionResponseHandler((hrm) => bar = true)));

            registry.SetHandler<AboutLink>(grh);

            var link = registry.CreateLink<AboutLink>();
            link.Target = new Uri("http://example.org");
            var httpClient = new HttpClient(new FakeHandler() { Response = new HttpResponseMessage()});

            return httpClient.FollowLinkAsync(link).ContinueWith(t =>
                {
                    Assert.True(foo);
                    Assert.True(bar);
                    Assert.True(baz);
                });
        }
开发者ID:rollingthunder,项目名称:Link,代码行数:24,代码来源:LinkRegistryTests.cs

示例10: FollowLink

        public async Task FollowLink()
        {
            var link = new Link { Target = new Uri("Http://localhost") };
            var client = new HttpClient(new FakeMessageHandler());

            var uri = string.Empty;
            var machine = new HttpResponseMachine();
            machine.When(HttpStatusCode.OK)
                .Then(async (rel,r) => {uri = r.RequestMessage.RequestUri.AbsoluteUri; });
            await client.FollowLinkAsync(link,machine);

            Assert.Equal("http://localhost/", uri);
        }
开发者ID:hapikit,项目名称:hapikit.net,代码行数:13,代码来源:LinkTests.cs

示例11: TypedLinksFromGenericType

        private static async Task TypedLinksFromGenericType()
        {
            var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders
                .UserAgent.Add(new ProductInfoHeaderValue("DarrelsGitClient", "1.0"));

            // Factory for typed links
            var linkFactory = new LinkFactory();
            GitHubHelper.RegisterGitHubLinks(linkFactory);

            // Get Home Document, without strongly typed object
            var homelink = new HomeLink();
            var homeResponse = await httpClient.FollowLinkAsync(homelink);
            var githubDocument = await homeResponse.Content.ReadAsGithubDocumentAsync(linkFactory);

            // Retrieve specific link from generic document
            var codeSearchLink = githubDocument.GetLink<CodeSearchLink>();
            codeSearchLink.Query = ".Result user:darrelmiller";

            var responseMessage = await httpClient.FollowLinkAsync(codeSearchLink);
            var githubDocument2 = await responseMessage.Content.ReadAsGithubDocumentAsync();
            var searchResults = CodeSearchLink.InterpretMessageBody(githubDocument2);

            // Show Results
            foreach (var result in searchResults.Items)
            {
                Console.WriteLine(result.Path);
            }
        }
开发者ID:hapikit,项目名称:github.net.hapikit,代码行数:29,代码来源:Program.cs

示例12: Returns_content_if_response_is_OK

        public Task Returns_content_if_response_is_OK()
        {
            string content = Guid.NewGuid().ToString();
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StringContent(content);

            var httpClient = new HttpClient(new FakeHandler
            {
                Response = response,
                InnerHandler = new HttpClientHandler()
            });

            var link = new GuidServiceLink();
            return httpClient.FollowLinkAsync(link).ContinueWith(
                t => Assert.Equal(content, link.Guid));
        }
开发者ID:rollingthunder,项目名称:Link,代码行数:16,代码来源:GuidServiceLinkTest.cs

示例13: FollowLink

        public void FollowLink()
        {
            var link = new Link { Target = new Uri("Http://localhost") };
            var client = new HttpClient(new FakeMessageHandler());

            var uri = string.Empty;
            link.HttpResponseHandler = new ActionResponseHandler(r => uri = r.RequestMessage.RequestUri.AbsoluteUri);
            var task = client.FollowLinkAsync(link);

            task.Wait();

            Assert.Equal("http://localhost/", uri);
        }
开发者ID:rollingthunder,项目名称:Link,代码行数:13,代码来源:LinkTests.cs


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