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


C# HttpRequestMessage.GetQueryNameValuePairs方法代码示例

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


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

示例1: Build

        public static RaygunRequestMessage Build(HttpRequestMessage request, RaygunRequestMessageOptions options)
        {
            var message = new RaygunRequestMessage();

              options = options ?? new RaygunRequestMessageOptions();

              message.HostName = request.RequestUri.Host;
              message.Url = request.RequestUri.AbsolutePath;
              message.HttpMethod = request.Method.ToString();
              message.IPAddress = GetIPAddress(request);
              message.Form = ToDictionary(request.GetQueryNameValuePairs(), options.IsFormFieldIgnored);
              message.QueryString = ToDictionary(request.GetQueryNameValuePairs(), s => false);

              SetHeaders(message, request, options.IsHeaderIgnored);

              if (!options.IsRawDataIgnored)
              {
            string contentType = null;
            if (message.Headers != null && message.Headers.Contains("Content-Type"))
            {
              contentType = (string)message.Headers["Content-Type"];
            }

            if (contentType == null || CultureInfo.InvariantCulture.CompareInfo.IndexOf(contentType, "application/x-www-form-urlencoded", CompareOptions.IgnoreCase) < 0)
            {
              object body;
              if (request.Properties.TryGetValue(RaygunWebApiDelegatingHandler.RequestBodyKey, out body))
              {
            message.RawData = body.ToString();
              }
            }
              }

              return message;
        }
开发者ID:nelsonsar,项目名称:raygun4net,代码行数:35,代码来源:RaygunWebApiRequestMessageBuilder.cs

示例2: SendAsync

        protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request.Headers.Authorization != null)
            {
                if (string.Equals(request.Headers.Authorization.Scheme, AuthenticationType, StringComparison.InvariantCultureIgnoreCase))
                {
                    string authToken = request.Headers.Authorization.Parameter;

                    // validate Token here
                    HandleAuthData(request, authToken);
                }
            } else // try query string parameters to find token
            {
                var authTokenFound = request.GetQueryNameValuePairs()
                    .Any(k => k.Key == QueryStringAuthHolderKey);

                if (authTokenFound)
                {
                    var tokenKvp = request.GetQueryNameValuePairs()
                        .First(k => k.Key == QueryStringAuthHolderKey);

                    HandleAuthData(request, tokenKvp.Value);
                }
            }

            var innerResult = await base.SendAsync(request, cancellationToken);

            return innerResult;
        }
开发者ID:gubenkoved,项目名称:photo-galery,代码行数:29,代码来源:AuthMessageHandler.cs

示例3: ReadGetAsync

        public async Task<FlowRequest> ReadGetAsync(HttpRequestMessage request)
        {
            Dictionary<string, string> dictionary = request.GetQueryNameValuePairs()
                .ToDictionary(x => x.Key, x => x.Value);

            return Create(dictionary);
        }
开发者ID:pekkah,项目名称:Tanka.FileSystem.WebApi,代码行数:7,代码来源:FlowRequestReader.cs

示例4: ExtractSortExpressions

 public string[] ExtractSortExpressions(HttpRequestMessage requestMessage)
 {
     var queryParams = requestMessage.GetQueryNameValuePairs();
     var sortParam = queryParams.FirstOrDefault(kvp => kvp.Key == SortQueryParamKey);
     if (sortParam.Key != SortQueryParamKey) return new string[] {};
     return sortParam.Value.Split(',');
 }
开发者ID:vearsa,项目名称:JSONAPI.NET,代码行数:7,代码来源:DefaultSortExpressionExtractor.cs

示例5: SendAsync

        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var response = await base.SendAsync(request, cancellationToken);
            if(!response.IsSuccessStatusCode)
            {
                // There was an error earlier in the pipeline so we just return the result as normal
                return response;
            }

            var content = response.Content as ObjectContent;
            if (content == null || content.Value == null)
            {
                // There is no object model for us to manipulate so there is nothing we can do.
                return response;
            }

            var requestedFields = _queryStringParser.GetRequestedFields(request.GetQueryNameValuePairs());
            if(!requestedFields.Any())
            {
                // The client has not specified any fields so just return the entire response to them as normal.
                return response;
            }

            var model = CreateDynamicObject(content.Value);
            FilterFields(model, requestedFields);

            var filteredResponse = request.CreateResponse(model);
            foreach (var header in response.Headers)
            {
                filteredResponse.Headers.Add(header.Key, header.Value);
            }

            return filteredResponse;
        }
开发者ID:jaredrussell,项目名称:Amikiri,代码行数:34,代码来源:PartialResponseHandler.cs

示例6: ODataQueryOptions

        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from 
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information</param>
        /// <param name="request">The incoming request message</param>
        public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            // remember the context
            Context = context;

            // Parse the query from request Uri
            RawValues = new ODataRawQueryOptions();
            IEnumerable<KeyValuePair<string, string>> queryParameters = request.GetQueryNameValuePairs();
            foreach (KeyValuePair<string, string> kvp in queryParameters)
            {
                switch (kvp.Key)
                {
                    case "$filter":
                        RawValues.Filter = kvp.Value;
                        ThrowIfEmpty(kvp.Value, "$filter");
                        Filter = new FilterQueryOption(kvp.Value, context);
                        break;
                    case "$orderby":
                        RawValues.OrderBy = kvp.Value;
                        ThrowIfEmpty(kvp.Value, "$orderby");
                        OrderBy = new OrderByQueryOption(kvp.Value, context);
                        break;
                    case "$top":
                        RawValues.Top = kvp.Value;
                        ThrowIfEmpty(kvp.Value, "$top");
                        Top = new TopQueryOption(kvp.Value, context);
                        break;
                    case "$skip":
                        RawValues.Skip = kvp.Value;
                        ThrowIfEmpty(kvp.Value, "$skip");
                        Skip = new SkipQueryOption(kvp.Value, context);
                        break;
                    case "$select":
                        RawValues.Select = kvp.Value;
                        break;
                    case "$inlinecount":
                        RawValues.InlineCount = kvp.Value;
                        break;
                    case "$expand":
                        RawValues.Expand = kvp.Value;
                        break;
                    case "$skiptoken":
                        RawValues.SkipToken = kvp.Value;
                        break;
                    default:
                        // we don't throw if we can't recognize the query
                        break;
                }
            }
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:66,代码来源:ODataQueryOptions.cs

示例7: ParseQueryStringParameters

 /// <summary>
 /// The parseQueryStringParameters method parses the string and sets some fields according to the result
 /// </summary>
 /// <param name="request">The request parameter</param>
 /// <param name="controller">The controller parameter</param>        
 private void ParseQueryStringParameters(HttpRequestMessage request, AnetApiController controller)
 {
     var queryStringPairs = request.GetQueryNameValuePairs();
     
     foreach (var pair in queryStringPairs)
     {
         switch (pair.Key)
         {
             case Constants.QueryParameters.Fields:
                 this.ParseDataShapingParameters(controller, pair); 
                 break;
             case Constants.QueryParameters.Offset:
                 this.ParsePageParameters(controller, pair); 
                 break;
             case Constants.QueryParameters.Limit:
                 this.ParsePageParameters(controller, pair); 
                 break;
             case Constants.QueryParameters.PageSize:
                 this.ParsePageParameters(controller, pair); 
                 break;
             case Constants.QueryParameters.PageNumber:
                 this.ParsePageParameters(controller, pair); 
                 break;
             case Constants.QueryParameters.SortKey:
                 this.ParseSortParameters(controller, pair); 
                 break;
             case Constants.QueryParameters.SortOrder:
                 this.ParseSortParameters(controller, pair); 
                 break;
             case Constants.QueryParameters.Filter:
                 this.ParseFilterParameters(controller, pair); 
                 break;
         }
     }
 }
开发者ID:gauravmokhasi,项目名称:EventFrameworkPOC,代码行数:40,代码来源:AnetApiQueryParserAttribute.cs

示例8: Match

        public override bool Match(
            HttpRequestMessage request,
            IHttpRoute route,
            string parameterName,
            IDictionary<string, object> values,
            HttpRouteDirection routeDirection)
        {
            foreach (string key in HeaderConstraints.Keys)
            {
                if (!request.Headers.Contains(key)
                    || string.Compare(request.Headers.GetValues(key).FirstOrDefault(), HeaderConstraints[key].ToString(), true) != 0)
                {
                    return false;
                }
            }

            var queries = request.GetQueryNameValuePairs().ToDictionary(p => p.Key, p => p.Value);
            foreach (var key in QueryStringConstraints.Keys)
            {
                if (!queries.ContainsKey(key)
                    || string.Compare(queries[key], QueryStringConstraints[key].ToString(), true) != 0)
                {
                    return false;
                }
            }

            return base.Match(request, route, parameterName, values, routeDirection);
        }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:28,代码来源:ODataVersionRouteConstraint.cs

示例9: GetApiKeyFromQueryString

 private static string GetApiKeyFromQueryString(HttpRequestMessage request)
 {
     return request.GetQueryNameValuePairs()
         .Where(pair => pair.Key == "apikey")
         .Select(pair => pair.Value)
         .FirstOrDefault();
 }
开发者ID:jrotello,项目名称:IntroToWebApi,代码行数:7,代码来源:ApiKeyHandler.cs

示例10: AddOAuthHeader

        /// <summary>
        /// Add OAuth 1.0 Authorization Header to the request 
        /// </summary>
        public override async Task AddOAuthHeader(HttpRequestMessage request)
        {
            // Try to get token result from request. If not found make call to Gateway to get the token.
            if (!this.TryGetTokenResultFromHeader(out tokenResult))
            {
                this.tokenResult = await this.GetTokenResultAsync();
            }

            if(this.tokenResult == null || this.tokenResult.Properties == null)
            {
                Logger.LogError(request, false, "Token result or properties returned are null");
                throw new UnauthorizedAccessException(CommonResource.AccessTokenNotFound);
            }

            if (!this.tokenResult.Properties.ContainsKey("AccessToken"))
            {
                Logger.LogError(request, false, "Couldn't find AccessToken in OAuth TokenResult.");
                throw new UnauthorizedAccessException(CommonResource.AccessTokenNotFound);
            }

            if (!this.tokenResult.Properties.ContainsKey("ConsumerKey"))
            {
                Logger.LogError(request, false, "Couldn't find ConsumerKey in OAuth TokenResult.");
                throw new UnauthorizedAccessException(CommonResource.AccessTokenInvalid);
            }

            if (!this.tokenResult.Properties.ContainsKey("AccessTokenSecret"))
            {
                Logger.LogError(request, false, "Couldn't find AccessTokenSecret in OAuth TokenResult.");
                throw new UnauthorizedAccessException(CommonResource.AccessTokenInvalid);
            }

            Dictionary<string, string> arguments = new Dictionary<string, string>();
            foreach (KeyValuePair<string, string> pair in request.GetQueryNameValuePairs())
            {
                if (!string.IsNullOrEmpty(pair.Value))
                {
                    arguments.Add(pair.Key, pair.Value);
                }
            }

            Uri baseUrl = new Uri(request.RequestUri.GetLeftPart(UriPartial.Path));

            string nonce = GenerateNonce();
            string timestamp = GenerateTimestamp();
            string signature = await this.GenerateSignature(request.Method, baseUrl, nonce, timestamp, arguments);

            string authHeader = string.Format(CultureInfo.InvariantCulture,
                                            AuthHeaderFormatOAuth1,
                                            Uri.EscapeDataString(this.tokenResult.Properties["AccessToken"]),
                                            Uri.EscapeDataString(nonce),
                                            Uri.EscapeDataString(this.tokenResult.Properties["ConsumerKey"]),
                                            Uri.EscapeDataString(HashAlgorithm),
                                            Uri.EscapeDataString(timestamp),
                                            Uri.EscapeDataString(Version),
                                            Uri.EscapeDataString(signature));

            request.Headers.Add(AuthorizationHeader, authHeader);
        }
开发者ID:sudarsanan-krishnan,项目名称:DynamicsCRMConnector,代码行数:62,代码来源:OAuth1Controller.cs

示例11: GetQueryValue

 private static string GetQueryValue(HttpRequestMessage request)
 {
     var pair = request.GetQueryNameValuePairs()
         .FirstOrDefault(kvp => kvp.Key.ToUpperInvariant().Equals(PartialResponseQueryParameterKey));
     return object.Equals(pair, default(System.Collections.Generic.KeyValuePair<string,string>))
         ? null
         : pair.Value;
 }
开发者ID:mhudasch,项目名称:MvcWebApiExtensions,代码行数:8,代码来源:PartialResponseAttribute.cs

示例12: SendAsync

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, 
            CancellationToken cancellationToken)
        {
            // the fall back language
            var langauges = new List<StringWithQualityHeaderValue>();

            // Check the AcceptLanguage simulated header in the query string first. This will ignore lettercase.
            NameValueCollection query = request.GetQueryNameValuePairs()
                .Aggregate(new NameValueCollection(), (col, kvp) =>
                {
                    col.Add(kvp.Key, kvp.Value);
                    return col;
                });

            if (query[FallbackHeaderConstants.AcceptLanguage] != null)
            {
                langauges.Add(new StringWithQualityHeaderValue(query[FallbackHeaderConstants.AcceptLanguage], 1.0));
            }
            else if (request.Headers.AcceptLanguage != null)
            {
                // then check the Accept-Language header.
                langauges.AddRange(request.Headers.AcceptLanguage);
            }

            langauges = langauges.OrderByDescending(l => l.Quality).ToList();

            // this is the final fall-back culture.
            var culture = CultureInfo.DefaultThreadCurrentCulture;
            var uiCulture = CultureInfo.DefaultThreadCurrentUICulture;

            // try to break and find one language that's available
            foreach (StringWithQualityHeaderValue lang in langauges)
            {
                try
                {
                    culture = CultureInfo.GetCultureInfo(lang.Value);
                    uiCulture = culture;
                    break;
                }
                catch (CultureNotFoundException)
                {
                    // ignore the error
                }
            }

            if (_setThreadCulture)
            {
                Thread.CurrentThread.CurrentCulture = culture ?? _lastResortFallback;
            }
            if (_setThreadUiCulture)
            {
                Thread.CurrentThread.CurrentUICulture = uiCulture ?? _lastResortFallback;
            }

            return base.SendAsync(request, cancellationToken);
        }
开发者ID:stevenaw,项目名称:climax-web-http,代码行数:56,代码来源:ThreadCultureMessageHandler.cs

示例13: HttpRequestDetails

    public HttpRequestDetails(HttpRequestMessage message, RaygunRequestMessageOptions options = null)
    {
      options = options ?? new RaygunRequestMessageOptions();

      RequestUri = message.RequestUri;
      Method = message.Method;
      Form = ToDictionary(message.GetQueryNameValuePairs(), options.IsFormFieldIgnored);
      IPAddress = GetIPAddress(message);
      SetHeadersAndRawData(message, options.IsHeaderIgnored);
    }
开发者ID:ArturDorochowicz,项目名称:raygun4net,代码行数:10,代码来源:RaygunWebApiRequestMessage.cs

示例14: VersionFromApiKey

        private static string VersionFromApiKey(HttpRequestMessage request)
        {
            foreach (var param in request.GetQueryNameValuePairs())
            {
                if (param.Key.ToLower() == "api_key")
                    return param.Value;
            }

            return "2.0";
        }
开发者ID:rodrigograudo,项目名称:Swashbuckle,代码行数:10,代码来源:SwaggerConfig.cs

示例15: GetPerRequestFormatterInstance

        public override MediaTypeFormatter GetPerRequestFormatterInstance(Type type, HttpRequestMessage request, MediaTypeHeaderValue mediaType)
        {
            var pairs = request.GetQueryNameValuePairs();
            if (pairs.Any(p => p.Key == "envelope" && p.Value == "false"))
            {
                return jsonMediaTypeFormatter;
            }

            return envelopeJsonMediaTypeFormatter;
        }
开发者ID:random-username,项目名称:emvelope,代码行数:10,代码来源:EmvelopeMediaTypeFormatter.cs


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