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


C# RestClient.BuildUri方法代码示例

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


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

示例1: POST_with_leading_slash_and_baseurl_trailing_slash

        public void POST_with_leading_slash_and_baseurl_trailing_slash()
        {
            RestRequest request = new RestRequest("/resource", Method.POST);
            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }
开发者ID:CL0SeY,项目名称:RestSharp,代码行数:9,代码来源:UrlBuilderTests.cs

示例2: POST_with_leading_slash

        public void POST_with_leading_slash()
        {
            var request = new RestRequest("/resource", Method.POST);
            var client = new RestClient(new Uri("http://example.com"));
            var expected = new Uri("http://example.com/resource");
            var output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }
开发者ID:xw616525957,项目名称:RestSharp,代码行数:9,代码来源:UrlBuilderTests.cs

示例3: GET_with_leading_slash

        public void GET_with_leading_slash()
        {
            RestRequest request = new RestRequest("/resource");
            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }
开发者ID:CL0SeY,项目名称:RestSharp,代码行数:9,代码来源:UrlBuilderTests.cs

示例4: GET_with_empty_request_and_bare_hostname

        public void GET_with_empty_request_and_bare_hostname()
        {
            var request = new RestRequest();
            var client = new RestClient("http://example.com");

            var expected = new Uri("http://example.com/");
            var output = client.BuildUri(request);

            Assert.Equal(expected, output);
        }
开发者ID:ryno1234,项目名称:RestSharp,代码行数:10,代码来源:UrlBuilderTests.cs

示例5: GET_with_resource_containing_slashes

        public void GET_with_resource_containing_slashes()
        {
            var request = new RestRequest("resource/foo");
            var client = new RestClient("http://example.com");

            var expected = new Uri("http://example.com/resource/foo");
            var output = client.BuildUri(request);

            Assert.Equal(expected, output);
        }
开发者ID:kevinmcmahon,项目名称:RestSharp,代码行数:10,代码来源:UrlBuilderTests.cs

示例6: GET_with_empty_request

        public void GET_with_empty_request()
        {
            var request = new RestRequest();
            var client = new RestClient("http://example.com/resource");

            var expected = new Uri("http://example.com/resource");
            var output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }
开发者ID:RestRT,项目名称:RestRT,代码行数:10,代码来源:UrlBuilderTests.cs

示例7: GET_with_leading_slash_and_baseurl_trailing_slash

        public void GET_with_leading_slash_and_baseurl_trailing_slash()
        {
            var request = new RestRequest("/resource");
            request.AddParameter("foo", "bar");
            var client = new RestClient("http://example.com/");

            var expected = new Uri("http://example.com/resource?foo=bar");
            var output = client.BuildUri(request);

            Assert.Equal(expected, output);
        }
开发者ID:kevinmcmahon,项目名称:RestSharp,代码行数:11,代码来源:UrlBuilderTests.cs

示例8: GET_with_resource_containing_tokens

        public void GET_with_resource_containing_tokens()
        {
            var request = new RestRequest("resource/{foo}");
            request.AddUrlSegment("foo", "bar");
            var client = new RestClient("http://example.com");

            var expected = new Uri("http://example.com/resource/bar");
            var output = client.BuildUri(request);

            Assert.Equal(expected, output);
        }
开发者ID:kevinmcmahon,项目名称:RestSharp,代码行数:11,代码来源:UrlBuilderTests.cs

示例9: Can_Authenticate_With_OAuth

        //[Test]
        public void Can_Authenticate_With_OAuth()
        {
            Uri baseUrl = new Uri("https://api.twitter.com");
            RestClient client = new RestClient(baseUrl)
                                {
                                    Authenticator = OAuth1Authenticator.ForRequestToken("CONSUMER_KEY", "CONSUMER_SECRET")
                                };
            RestRequest request = new RestRequest("oauth/request_token");
            IRestResponse response = client.Execute(request);

            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            NameValueCollection qs = HttpUtility.ParseQueryString(response.Content);
            string oauthToken = qs["oauth_token"];
            string oauthTokenSecret = qs["oauth_token_secret"];

            Assert.NotNull(oauthToken);
            Assert.NotNull(oauthTokenSecret);

            request = new RestRequest("oauth/authorize?oauth_token=" + oauthToken);

            string url = client.BuildUri(request)
                               .ToString();

            Process.Start(url);

            const string verifier = "123456"; // <-- Breakpoint here (set verifier in debugger)

            request = new RestRequest("oauth/access_token");
            client.Authenticator = OAuth1Authenticator.ForAccessToken(
                "P5QziWtocYmgWAhvlegxw", "jBs07SIxJ0kodeU9QtLEs1W1LRgQb9u5Lc987BA94", oauthToken,
                oauthTokenSecret, verifier);
            response = client.Execute(request);

            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            qs = HttpUtility.ParseQueryString(response.Content);
            oauthToken = qs["oauth_token"];
            oauthTokenSecret = qs["oauth_token_secret"];

            Assert.NotNull(oauthToken);
            Assert.NotNull(oauthTokenSecret);

            request = new RestRequest("account/verify_credentials.xml");
            client.Authenticator = OAuth1Authenticator.ForProtectedResource(
                "P5QziWtocYmgWAhvlegxw", "jBs07SIxJ0kodeU9QtLEs1W1LRgQb9u5Lc987BA94", oauthToken,
                oauthTokenSecret);
            response = client.Execute(request);

            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
开发者ID:CL0SeY,项目名称:RestSharp,代码行数:55,代码来源:AuthenticationTests.cs

示例10: Should_not_duplicate_question_mark

        public void Should_not_duplicate_question_mark()
        {
            RestRequest request = new RestRequest();

            request.AddParameter("param2", "value2");

            RestClient client = new RestClient("http://example.com/resource?param1=value1");
            Uri expected = new Uri("http://example.com/resource?param1=value1&param2=value2");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }
开发者ID:CL0SeY,项目名称:RestSharp,代码行数:12,代码来源:UrlBuilderTests.cs

示例11: TestOnlyDefaultParameter

        public void TestOnlyDefaultParameter()
        {
            using (var client = new RestClient("http://localhost"))
            {
                client.AddDefaultParameter("param1", "value1");

                var request = new RestRequest();

                var uri = client.BuildUri(request).ToString();
                Assert.Equal("http://localhost/?param1=value1", uri);
            }
        }
开发者ID:yuleyule66,项目名称:restsharp.portable,代码行数:12,代码来源:RequestParameterTests.cs

示例12: TestIssue16

        public void TestIssue16(Type factoryType)
        {
            using (var client = new RestClient("http://httpbin.org/")
            {
                HttpClientFactory = CreateClientFactory(factoryType, false),
            })
            {
                var request = new RestRequest("get?a={a}");
                request.AddParameter("a", "value-of-a", ParameterType.UrlSegment);

                Assert.Equal("http://httpbin.org/get?a=value-of-a", client.BuildUri(request).ToString());
            }
        }
开发者ID:sloncho,项目名称:restsharp.portable,代码行数:13,代码来源:IssueTests.cs

示例13: GET_wth_trailing_slash_and_query_parameters

        public void GET_wth_trailing_slash_and_query_parameters()
        {
            var request = new RestRequest("/resource/");
            var client = new RestClient("http://example.com");

            request.AddParameter("foo", "bar");

            var expected = new Uri("http://example.com/resource/?foo=bar");
            var output = client.BuildUri(request);
            var response = client.Execute(request);

            Assert.Equal(expected, output);
        }
开发者ID:propagated,项目名称:RestSharp,代码行数:13,代码来源:UrlBuilderTests.cs

示例14: Can_Authenticate_With_OAuth

        public void Can_Authenticate_With_OAuth()
        {
            const string consumerKey = "";
            const string consumerSecret = "";

            var baseUrl = "https://api.twitter.com";
            var client = new RestClient(baseUrl);
            client.Authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret);
            var request = new RestRequest("oauth/request_token", Method.POST);
            var response = client.Execute(request);

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var qs = HttpUtility.ParseQueryString(response.Content);
            var oauth_token = qs["oauth_token"];
            var oauth_token_secret = qs["oauth_token_secret"];
            Assert.NotNull(oauth_token);
            Assert.NotNull(oauth_token_secret);

            request = new RestRequest("oauth/authorize");
            request.AddParameter("oauth_token", oauth_token);
            var url = client.BuildUri(request).ToString();
            Process.Start(url);

            var verifier = "123456"; // <-- Breakpoint here (set verifier in debugger)
            request = new RestRequest("oauth/access_token");
            client.Authenticator = OAuth1Authenticator.ForAccessToken(
                consumerKey, consumerSecret, oauth_token, oauth_token_secret, verifier
            );
            response = client.Execute(request);

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            qs = HttpUtility.ParseQueryString(response.Content);
            oauth_token = qs["oauth_token"];
            oauth_token_secret = qs["oauth_token_secret"];
            Assert.NotNull(oauth_token);
            Assert.NotNull(oauth_token_secret);

            request = new RestRequest("account/verify_credentials.xml");
            client.Authenticator = OAuth1Authenticator.ForProtectedResource(
                consumerKey, consumerSecret, oauth_token, oauth_token_secret
            );

            response = client.Execute(request);

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
开发者ID:cboyce428,项目名称:RestSharp,代码行数:51,代码来源:oAuth1Tests.cs

示例15: TestParameterOverride

        public void TestParameterOverride()
        {
            using (var client = new RestClient("http://localhost"))
            {
                client.AddDefaultParameter("param1", "value1");

                var request = new RestRequest();
                request
                    .AddParameter("param2", "value2")
                    .AddOrUpdateParameter("param1", "value1.1");

                var uri = client.BuildUri(request).ToString();
                Assert.Equal("http://localhost/?param1=value1.1&param2=value2", uri);
            }
        }
开发者ID:yuleyule66,项目名称:restsharp.portable,代码行数:15,代码来源:RequestParameterTests.cs


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