本文整理汇总了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);
}
示例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);
}
}
示例3: CopyTo
internal static void CopyTo(this HttpContentHeaders from, HttpContentHeaders to)
{
foreach (var header in from)
{
to.TryAddWithoutValidation(header.Key, header.Value);
}
}
示例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);
}
示例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);
}
}
示例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));
}
示例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));
}
示例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);
}
}
}