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


C# RestRequest.AddHeader方法代码示例

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


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

示例1: Cannot_Set_Invalid_Host_Header

        public void Cannot_Set_Invalid_Host_Header(string value)
        {
            RestRequest request = new RestRequest();
            ArgumentException exception = Assert.Throws<ArgumentException>(() => request.AddHeader("Host", value));

            Assert.AreEqual("value", exception.ParamName);
        }
开发者ID:godlzr,项目名称:RestSharp,代码行数:7,代码来源:RestRequestTests.cs

示例2: DelegateWith

        public static RestRequest DelegateWith(RestClient client, RestRequest request)
        {
            if(request == null)
            {
                throw new ArgumentNullException("request");
            }

            if(!request.Method.HasValue)
            {
                throw new ArgumentException("Request must specify a web method.");
            }

            var method = request.Method.Value;
            var credentials = (OAuthCredentials)request.Credentials;
            var url = request.BuildEndpoint(client).ToString();
            var workflow = new OAuthWorkflow(credentials);
            var uri = new Uri(client.Authority);
            var realm = uri.Host;
            var enableTrace = client.TraceEnabled || request.TraceEnabled;

            var info = workflow.BuildProtectedResourceInfo(method, request.GetAllHeaders(), url);
            var query = credentials.GetQueryFor(url, request, info, method, enableTrace);
            ((OAuthWebQuery) query).Realm = realm;
            var auth = query.GetAuthorizationContent();

            var echo = new RestRequest();
            echo.AddHeader("X-Auth-Service-Provider", url);
            echo.AddHeader("X-Verify-Credentials-Authorization", auth);
            return echo;
        }
开发者ID:rakkeh,项目名称:hammock,代码行数:30,代码来源:OAuthCredentials.cs

示例3: Cannot_Set_Empty_Host_Header

        public void Cannot_Set_Empty_Host_Header()
        {
            var request = new RestRequest();
            var exception = Assert.Throws<ArgumentException>(() => request.AddHeader("Host", string.Empty));

            Assert.AreEqual("value", exception.ParamName);
        }
开发者ID:xw616525957,项目名称:RestSharp,代码行数:7,代码来源:RestRequestTests.cs

示例4: ShouldParseOutRangeSpecifier

 public void ShouldParseOutRangeSpecifier()
 {
     var restClient = new RestClient("http://localhost");
     var req = new RestRequest("bob", Method.GET);
     
     req.AddHeader("Range", "pages=1-2");
     var resp = restClient.Execute(req);
 }
开发者ID:dgreenbean,项目名称:RestSharp,代码行数:8,代码来源:AddRangeTests.cs

示例5: TestRequestParameter

        public async Task TestRequestParameter(Type factoryType)
        {
            using (var client = new RestClient("http://httpbin.org/")
            {
                HttpClientFactory = CreateClientFactory(factoryType, false),
            })
            {
                var request = new RestRequest("post", Method.POST);
                request.AddHeader("Restsharp-Test1", "TestValue1");
                request.AddParameter("param1", "ParamValue1");

                var response = await client.Execute<HttpBinResponse>(request);
                Assert.Equal("ParamValue1", response.Data.Form["param1"]);
                Assert.Equal("TestValue1", response.Data.Headers["Restsharp-Test1"]);
            }
        }
开发者ID:yuleyule66,项目名称:restsharp.portable,代码行数:16,代码来源:PostHeaderRequestTests.cs

示例6: Set_Auth_Header_Only_Once

        public void Set_Auth_Header_Only_Once()
        {
            var client = new RestClient();
            var request = new RestRequest();

            request.AddHeader("Authorization", this.expectedAuthHeaderContent);

            client.Authenticator = new JwtAuthenticator("second_header_auth_token");

            //In real case client.Execute(...) will invoke Authenticate method
            client.Authenticator.Authenticate(client, request);

            var paramList = request.Parameters.FindAll(p => p.Name.Equals("Authorization"));

            Assert.AreEqual(1, paramList.Count);

            var authParam = paramList[0];

            Assert.True(authParam.Type == ParameterType.HttpHeader);
            Assert.AreEqual(this.expectedAuthHeaderContent, authParam.Value);
            Assert.AreNotEqual("second_header_auth_token", authParam.Value);
        }
开发者ID:xw616525957,项目名称:RestSharp,代码行数:22,代码来源:JwtAuthTests.cs

示例7: Can_Set_Valid_Host_Header

        public void Can_Set_Valid_Host_Header(string value)
        {
            RestRequest request = new RestRequest();

            Assert.DoesNotThrow(() => request.AddHeader("Host", value));
        }
开发者ID:godlzr,项目名称:RestSharp,代码行数:6,代码来源:RestRequestTests.cs

示例8: AddOAuthData

        private void AddOAuthData(RestClient client, RestRequest request, OAuthWorkflow workflow)
        {
            var url = client.BuildUri(request).ToString();

            OAuthWebQueryInfo oauth;
            var method = request.Method.ToString().ToUpperInvariant();

            var parameters = new WebParameterCollection();

            switch (Type)
            {
                case OAuthType.RequestToken:
                    workflow.RequestTokenUrl = url;
                    oauth = workflow.BuildRequestTokenInfo(method, parameters);
                    break;
                case OAuthType.AccessToken:
                    workflow.AccessTokenUrl = url;
                    oauth = workflow.BuildAccessTokenInfo(method, parameters);
                    break;
                case OAuthType.ClientAuthentication:
                    workflow.AccessTokenUrl = url;
                    oauth = workflow.BuildClientAuthAccessTokenInfo(method, parameters);
                    break;
                case OAuthType.ProtectedResource:
                    oauth = workflow.BuildProtectedResourceInfo(method, parameters, url);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            switch (ParameterHandling)
            {
                case OAuthParameterHandling.HttpAuthorizationHeader:
                    parameters.Add("oauth_signature", oauth.Signature);
                    request.AddHeader("Authorization", GetAuthorizationHeader(parameters));
                    break;
                case OAuthParameterHandling.UrlOrPostParameters:
                    parameters.Add("oauth_signature", HttpUtility.UrlDecode(oauth.Signature));
                    foreach (var parameter in parameters)
                    {
                        request.AddParameter(parameter.Name, parameter.Value);
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:apaz,项目名称:RestSharp,代码行数:47,代码来源:OAuth1Authenticator.cs

示例9: AddOAuthData

		private void AddOAuthData(RestClient client, RestRequest request, OAuthWorkflow workflow)
		{
			var url = client.BuildUri(request).ToString();
#if DEBUG
            Console.WriteLine("URL for OAUTH : "+url);
#endif
			OAuthWebQueryInfo oauth;
			var method = request.Method.ToString().ToUpperInvariant();

			var parameters = new WebParameterCollection();

			// for non-GET style requests make sure params are part of oauth signature
			if (request.Method != Method.GET && request.Method != Method.DELETE)
			{
				foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost))
				{
					parameters.Add(new WebPair(p.Name, p.Value.ToString()));
				}
			}

			switch (Type)
			{
				case OAuthType.RequestToken:
					workflow.RequestTokenUrl = url;
					oauth = workflow.BuildRequestTokenInfo(method, parameters);
					break;
				case OAuthType.AccessToken:
					workflow.AccessTokenUrl = url;
					oauth = workflow.BuildAccessTokenInfo(method, parameters);
					break;
				case OAuthType.ClientAuthentication:
					workflow.AccessTokenUrl = url;
					oauth = workflow.BuildClientAuthAccessTokenInfo(method, parameters);
					break;
				case OAuthType.ProtectedResource:
					oauth = workflow.BuildProtectedResourceInfo(method, parameters, url);
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}

			switch (ParameterHandling)
			{
				case OAuthParameterHandling.HttpAuthorizationHeader:
					parameters.Add("oauth_signature", oauth.Signature);
					request.AddHeader("Authorization", GetAuthorizationHeader(parameters));
					break;
				case OAuthParameterHandling.UrlOrPostParameters:
					parameters.Add("oauth_signature", HttpUtility.UrlDecode(oauth.Signature));
					foreach (var parameter in parameters)
					{
						request.AddParameter(parameter.Name, parameter.Value);
					}
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
开发者ID:MikeWarriner,项目名称:UrbanAirship.NET,代码行数:58,代码来源:OAuth1Authenticator.cs

示例10: TestIssue29_ContentTypeParameter

 public async Task TestIssue29_ContentTypeParameter(Type factoryType)
 {
     using (var client = new RestClient("http://httpbin.org/")
     {
         HttpClientFactory = CreateClientFactory(factoryType, false),
     })
     {
         var req = new RestRequest("post", Method.POST);
         req.AddParameter("a", "value-of-a");
         req.AddHeader("content-type", "application/x-www-form-urlencoded;charset=utf-8");
         var resp = await client.Execute<PostResponse>(req);
         Assert.NotNull(resp.Data);
         Assert.NotNull(resp.Data.Form);
         Assert.True(resp.Data.Form.ContainsKey("a"));
         Assert.Equal("value-of-a", resp.Data.Form["a"]);
     }
 }
开发者ID:sloncho,项目名称:restsharp.portable,代码行数:17,代码来源:IssueTests.cs

示例11: 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

示例12: AutomatedUnderwriting

        public void AutomatedUnderwriting(Int32 MerchantId, Int32 UnderwritingResultId)
        {
            try
            {
                String displayResults = "";

                using (ApplicationDbContext ctx = new ApplicationDbContext())
                {
                    if (ctx.Merchants.Any(m => m.RecordId == MerchantId) && ctx.UnderwritingResults.Any(ur => ur.RecordId == UnderwritingResultId))
                    {
                        var editMerchant = ctx.Merchants.First(m => m.RecordId == MerchantId);
                        var underwritingResults = ctx.UnderwritingResults.FirstOrDefault(ur => ur.RecordId == UnderwritingResultId);
                        var underwritingSchema = editMerchant.AdvancePlan.UnderwritingSchema;

                        if (editMerchant != null && underwritingResults != null)
                        {
                            String baseUrl = "";
                            String apiPath = "api/Underwriting";
                            XmlDocument xmlDoc = new XmlDocument();
                            String riskCodes = "";
                            String isDemo = "0";

                            if (!String.IsNullOrEmpty(_miqroSettings["d9444814-043a-44f2-982c-913c55d84746"]))
                            {
                                baseUrl = _miqroSettings["d9444814-043a-44f2-982c-913c55d84746"];

                                if (!String.IsNullOrEmpty(baseUrl))
                                {
                                    var client = new RestClient(baseUrl);
                                    var request = new RestRequest(apiPath, Method.POST);
                                    request.AddHeader("Accept", "application/xml");
                                    request.Parameters.Clear();

                                    request.AddParameter("CorpName", editMerchant.CorpName ?? "");
                                    request.AddParameter("DbaName", editMerchant.DbaName ?? "");
                                    request.AddParameter("FEIN", editMerchant.FedTaxId ?? "");
                                    if (editMerchant.Business != null)
                                    {
                                        request.AddParameter("CorpPhone", editMerchant.Business.HomePhone ?? "");
                                        if (editMerchant.Business.Address != null)
                                        {
                                            request.AddParameter("CorpAddress", editMerchant.Business.Address.Address ?? "");
                                            request.AddParameter("CorpCity", editMerchant.Business.Address.City ?? "");
                                            request.AddParameter("CorpState", editMerchant.Business.Address.State.Abbreviation ?? "");
                                            request.AddParameter("CorpZip", editMerchant.Business.Address.Zip ?? "");
                                        }
                                    }
                                    else
                                    {
                                        request.AddParameter("CorpPhone", "");
                                        request.AddParameter("CorpAddress", "");
                                        request.AddParameter("CorpCity", "");
                                        request.AddParameter("CorpState", "");
                                        request.AddParameter("CorpZip", "");
                                    }

                                    isDemo = _miqroSettings["3e1acfa5-73dd-4573-8f3c-e7e46aef39dc"] ?? "0";

                                    if (isDemo == "1")
                                    {
                                        request.AddParameter("ARFirst", editMerchant.MerchantPrincipal.Contact.FirstName);
                                        request.AddParameter("ARMiddle", editMerchant.MerchantPrincipal.Contact.MiddleInitial);
                                        request.AddParameter("ARLast", editMerchant.MerchantPrincipal.Contact.LastName);
                                        if (editMerchant.MerchantPrincipal.Contact != null && editMerchant.MerchantPrincipal.Contact.Address != null)
                                        {
                                            request.AddParameter("ARAddress", editMerchant.MerchantPrincipal.Contact.Address.Address ?? "");
                                            request.AddParameter("ARCity", editMerchant.MerchantPrincipal.Contact.Address.City ?? "");
                                            request.AddParameter("ARState", editMerchant.MerchantPrincipal.Contact.Address.State.Abbreviation ?? "");
                                            request.AddParameter("ARZip", editMerchant.MerchantPrincipal.Contact.Address.Zip ?? "");
                                        }
                                        else
                                        {
                                            request.AddParameter("ARAddress", "");
                                            request.AddParameter("ARCity", "");
                                            request.AddParameter("ARState", "");
                                            request.AddParameter("ARZip", "");
                                        }
                                        request.AddParameter("ARAge", "");
                                        if (editMerchant.MerchantPrincipal.PrincipalDoB.HasValue)
                                        {
                                            request.AddParameter("ARDoBYear", editMerchant.MerchantPrincipal.PrincipalDoB.Value.Year.ToString() ?? "");
                                            request.AddParameter("ARDoBMonth", editMerchant.MerchantPrincipal.PrincipalDoB.Value.Month.ToString() ?? "");
                                            request.AddParameter("ARDoBDay", editMerchant.MerchantPrincipal.PrincipalDoB.Value.Day.ToString() ?? "");
                                        }
                                        else
                                        {
                                            request.AddParameter("ARDoBYear", "");
                                            request.AddParameter("ARDoBMonth", "");
                                            request.AddParameter("ARDoBDay", "");
                                        }
                                        if (editMerchant.MerchantPrincipal.PrincipalSsn != null)
                                        {
                                            request.AddParameter("ARSSN", PWDTK.Utf8BytesToString(editMerchant.MerchantPrincipal.PrincipalSsn));
                                        }
                                        else
                                        {
                                            request.AddParameter("ARSSN", "");
                                        }
                                        if (editMerchant.MerchantPrincipal.PrincipalDLNumber != null)
                                        {
//.........这里部分代码省略.........
开发者ID:WCTingle,项目名称:InfoShare_Public,代码行数:101,代码来源:MerchantDetail.ascx.cs


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