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


C# HttpContentHeaders.TryAddWithoutValidation方法代码示例

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


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

示例1: ContentLength_UseAddMethod_AddedValueCanBeRetrievedUsingProperty

        public void ContentLength_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
        {
            _headers = new HttpContentHeaders(new ComputeLengthHttpContent(() => { throw new ShouldNotBeInvokedException(); }));
            _headers.TryAddWithoutValidation(HttpKnownHeaderNames.ContentLength, " 68 \r\n ");

            Assert.Equal(68, _headers.ContentLength);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:HttpContentHeadersTest.cs

示例2: CopyTo

		public static void CopyTo(this HttpContentHeaders fromHeaders, HttpContentHeaders toHeaders)
		{
			foreach (KeyValuePair<string, IEnumerable<string>> header in fromHeaders)
			{
				toHeaders.TryAddWithoutValidation(header.Key, header.Value);
			}
		}
开发者ID:Prolucid,项目名称:NuGet.Lucene,代码行数:7,代码来源:PackagesController.cs

示例3: CopyTo

 internal static void CopyTo(this HttpContentHeaders from, HttpContentHeaders to)
 {
     foreach (var header in from)
     {
         to.TryAddWithoutValidation(header.Key, header.Value);
     }
 }
开发者ID:D3-LucaPiombino,项目名称:WebAPI-Proxy,代码行数:7,代码来源:HeadersExtensions.cs

示例4: ContentLength_UseAddMethod_AddedValueCanBeRetrievedUsingProperty

        public void ContentLength_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
        {
            _headers = new HttpContentHeaders(() => { Assert.True(false, "Delegate called."); return 0; });
            _headers.TryAddWithoutValidation(HttpKnownHeaderNames.ContentLength, " 68 \r\n ");

            Assert.Equal(68, _headers.ContentLength);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:HttpContentHeadersTest.cs

示例5: CopyTo

        public static void CopyTo(this HttpContentHeaders fromHeaders, HttpContentHeaders toHeaders)
        {
            Contract.Assert(fromHeaders != null, "fromHeaders cannot be null.");
            Contract.Assert(toHeaders != null, "toHeaders cannot be null.");

            foreach (KeyValuePair<string, IEnumerable<string>> header in fromHeaders)
            {
                toHeaders.TryAddWithoutValidation(header.Key, header.Value);
            }
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:10,代码来源:HttpHeaderExtensions.cs

示例6: SetDefaultContentHeaders

        /// <inheritdoc/>
        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            // call base to validate parameters and set Content-Type header based on mediaType parameter.
            base.SetDefaultContentHeaders(type, headers, mediaType);

            headers.TryAddWithoutValidation(ODataServiceVersion, ODataUtils.ODataVersionToString(_version));
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:8,代码来源:ODataMediaTypeFormatter.cs

示例7: SetDefaultContentHeaders

        /// <inheritdoc/>
        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            if (type == null)
            {
                throw Error.ArgumentNull("type");
            }
            if (headers == null)
            {
                throw Error.ArgumentNull("headers");
            }

            // When the user asks for application/json we really need to set the content type to
            // application/json; odata.metadata=minimal. If the user provides the media type and is
            // application/json we are going to add automatically odata.metadata=minimal. Otherwise we are
            // going to fallback to the default implementation.

            // When calling this formatter as part of content negotiation the content negotiator will always
            // pick a non null media type. In case the user creates a new ObjectContent<T> and doesn't pass in a
            // media type, we delegate to the base class to rely on the default behavior. It's the user's 
            // responsibility to pass in the right media type.

            if (mediaType != null)
            {
                if (mediaType.MediaType.Equals("application/json", StringComparison.OrdinalIgnoreCase) &&
                    !mediaType.Parameters.Any(p => p.Name.Equals("odata.metadata", StringComparison.OrdinalIgnoreCase)))
                {
                    mediaType.Parameters.Add(new NameValueHeaderValue("odata.metadata", "minimal"));
                }

                headers.ContentType = (MediaTypeHeaderValue)((ICloneable)mediaType).Clone();
            }
            else
            {
                // This is the case when a user creates a new ObjectContent<T> passing in a null mediaType
                base.SetDefaultContentHeaders(type, headers, mediaType);
            }

            // In general, in Web API we pick a default charset based on the supported character sets
            // of the formatter. However, according to the OData spec, the service shouldn't be sending
            // a character set unless explicitly specified, so if the client didn't send the charset we chose
            // we just clean it.
            if (headers.ContentType != null &&
                !Request.Headers.AcceptCharset
                    .Any(cs => cs.Value.Equals(headers.ContentType.CharSet, StringComparison.OrdinalIgnoreCase)))
            {
                headers.ContentType.CharSet = String.Empty;
            }

            headers.TryAddWithoutValidation(
                HttpRequestMessageProperties.ODataServiceVersionHeader,
                ODataUtils.ODataVersionToString(_version));
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:53,代码来源:ODataMediaTypeFormatter.cs

示例8: SetDefaultContentHeaders

        /// <inheritdoc/>
        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            if (headers == null)
            {
                throw Error.ArgumentNull("headers");
            }

            // call base to validate parameters and set Content-Type header based on mediaType parameter.
            base.SetDefaultContentHeaders(type, headers, mediaType);

            ODataFormat format = GetODataFormat(headers);
            IEnumerable<KeyValuePair<string, string>> oDataHeaders = GetResponseMessageHeaders(type, format, _defaultODataVersion);

            foreach (KeyValuePair<string, string> pair in oDataHeaders)
            {
                // Special case Content-Type header so that we don't end up with two values for it
                // since base.SetDefaultContentHeaders could also have set it.
                if (String.Equals("Content-Type", pair.Key, StringComparison.OrdinalIgnoreCase))
                {
                    headers.ContentType = MediaTypeHeaderValue.Parse(pair.Value);
                }
                else
                {
                    headers.TryAddWithoutValidation(pair.Key, pair.Value);
                }
            }
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:28,代码来源:ODataMediaTypeFormatter.cs


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