本文整理汇总了C#中System.Net.Http.Headers.HttpContentHeaders.Add方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContentHeaders.Add方法的具体用法?C# HttpContentHeaders.Add怎么用?C# HttpContentHeaders.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.Headers.HttpContentHeaders
的用法示例。
在下文中一共展示了HttpContentHeaders.Add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContentLength_AddInvalidValueUsingUnusualCasing_ParserRetrievedUsingCaseInsensitiveComparison
public void ContentLength_AddInvalidValueUsingUnusualCasing_ParserRetrievedUsingCaseInsensitiveComparison()
{
_headers = new HttpContentHeaders(new ComputeLengthHttpContent(() => 15));
// Use uppercase header name to make sure the parser gets retrieved using case-insensitive comparison.
Assert.Throws<FormatException>(() => { _headers.Add("CoNtEnT-LeNgTh", "this is invalid"); });
}
示例2: CopyHeaders
private static void CopyHeaders(HttpContentHeaders fromHeaders,
HttpContentHeaders toHeaders)
{
foreach (KeyValuePair<string, IEnumerable<string>> header in fromHeaders) {
toHeaders.Add(header.Key, header.Value);
}
}
示例3: PopulateHeaders
public static void PopulateHeaders(this HttpPacket packet, HttpContentHeaders contentHeaders, HttpHeaders generalHeaders)
{
if (packet == null) throw new ArgumentNullException("packet");
string hdrKey;
foreach (var hdr in packet.Headers)
{
if (hdr.Key == null) continue;
hdrKey = hdr.Key.Trim().ToUpperInvariant();
if (hdrKey == "CONTENT-LENGTH") continue; //Content Length is automaitically calculated
if (Array.IndexOf<String>(contentOnlyHeaders, hdrKey) >= 0)
{
//TODO: Confirm if HttpResponseMessage/HttpRequestMessage will break headers into "," commas whereas in actuality header in Packet is an entire header
contentHeaders.Add(hdr.Key.Trim(), hdr.Value);
}
else
{
generalHeaders.Add(hdr.Key.Trim(), hdr.Value);
}
//TODO: Check if a string can be parsed properly into the typed header
//Test adding multiple headers of the same name will do. // Look up the Add overload that takes an ienumerable<string> to figure out its purpose.
}
}
示例4: PopulateHeaders
/// <summary>
/// Populates contentheaders and generalheaders with headers from the <see cref="HttpPacket"/>>
/// </summary>
/// <param name="packet"></param>
/// <param name="contentHeaders"></param>
/// <param name="generalHeaders"></param>
public static void PopulateHeaders(this HttpPacket packet, HttpContentHeaders contentHeaders, HttpHeaders generalHeaders)
{
if (packet == null) throw new ArgumentNullException("packet");
bool dateHeaderProcessed = false;
string hdrKey;
foreach (var hdr in packet.Headers)
{
if (hdr.Key == null) continue;
hdrKey = hdr.Key.Trim().ToUpperInvariant();
if (hdrKey == "CONTENT-LENGTH")
{
continue; //Content Length is automatically calculated by System.Net.Http.ByteArrayContent
}
else if (hdrKey == "DATE")
{
if (dateHeaderProcessed) continue; //Already Processed
dateHeaderProcessed = true;
//Date Header in wrong format causes exception in System.Net.Http.HttpResponseMessage/HttpRequestMessage
//TODO: Confirm that this exception still occurs in the newer Nuget version of System.Net.Http
//Check if the date string is in RFC 1123 format
var val = (hdr.Value == null || !hdr.Value.Any()) ? null : hdr.Value.First().Trim();
if(val != null && Common.Shared.IsValidHttpDate(val))
{
generalHeaders.Add("Date", val);
}
continue;
}
if (Array.IndexOf<String>(contentOnlyHeaders, hdrKey) >= 0)
{
contentHeaders.Add(hdr.Key.Trim(), hdr.Value);
}
else
{
generalHeaders.Add(hdr.Key.Trim(), hdr.Value);
}
}
}
示例5: CopyTo
/// <summary>Copies all headers from the source to the target.</summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="handleContentLength">true to handle content length.</param>
/// <param name="handleContentEncoding">true to handle content encoding.</param>
/// <param name="handleChangedValues">true to handle changed values.</param>
public static void CopyTo(
this HttpContentHeaders source,
HttpContentHeaders target,
bool handleContentLength = true,
bool handleContentEncoding = true,
bool handleChangedValues = false)
{
// Remove headers we are going to rewrite and headers with null values
foreach (var header in source)
{
try
{
if (!handleContentLength && header.Key.Equals("Content-Length", StringComparison.OrdinalIgnoreCase))
{
return;
}
if (!handleContentEncoding && header.Key.Equals("Content-Encoding", StringComparison.OrdinalIgnoreCase))
{
return;
}
if (!handleChangedValues)
{
// If values have changed, dont update it
if (target.Contains(header.Key))
{
if (target.GetValues(header.Key).Any(targetValue => header.Value.Any(originalValue => originalValue != targetValue)))
{
return;
}
}
}
target.Add(header.Key, header.Value);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
}
开发者ID:SneakyMax,项目名称:Microsoft.AspNet.WebApi.MessageHandlers.Compression,代码行数:48,代码来源:HttpContentHeaderExtensions.cs
示例6: SetDefaultContentHeaders
public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
{
base.SetDefaultContentHeaders(type, headers, mediaType);
string name = HttpContext.Current.Request.Url.Segments[HttpContext.Current.Request.Url.Segments.Length-1];
headers.Add("Content-Disposition", "attachment; filename=" + name + ".csv");
}
示例7: SetDefaultContentHeaders
public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
{
base.SetDefaultContentHeaders(type, headers, mediaType);
headers.Add("Content-Disposition", "attachment; filename=" + Filename);
}
示例8: SetDefaultContentHeaders
public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
{
base.SetDefaultContentHeaders(type, headers, mediaType);
headers.Add("Content-Disposition", string.Format("attachment; filename={0}", CsvFileName));
}
示例9: SetDefaultContentHeaders
/// <summary>Sets the default content headers.</summary>
/// <param name="type">The <see cref="Type"/>.</param>
/// <param name="headers">The <see cref="HttpContentHeaders"/>.</param>
/// <param name="mediaType">The <see cref="MediaTypeHeaderValue"/>.</param>
public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
{
headers.Add("Content-Disposition", "attachment; filename=\"" + type.Name + ".csv\"");
base.SetDefaultContentHeaders(type, headers, mediaType);
}
示例10: SetDefaultContentHeaders
public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
{
headers.Add(RestfulServiceConstants.RqModelTypeHeaderKey, EncryptionManager.Encrypt(type.AssemblyQualifiedName));
base.SetDefaultContentHeaders(type, headers, mediaType);
}