HttpMediaTypeWithQualityHeaderValueCollection 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 HTTP 请求上的 Accept HTTP 标头的值。
public ref class HttpMediaTypeWithQualityHeaderValueCollection sealed : IIterable<HttpMediaTypeWithQualityHeaderValue ^>, IVector<HttpMediaTypeWithQualityHeaderValue ^>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HttpMediaTypeWithQualityHeaderValueCollection final : IIterable<HttpMediaTypeWithQualityHeaderValue>, IVector<HttpMediaTypeWithQualityHeaderValue>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HttpMediaTypeWithQualityHeaderValueCollection final : IIterable<HttpMediaTypeWithQualityHeaderValue>, IVector<HttpMediaTypeWithQualityHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HttpMediaTypeWithQualityHeaderValueCollection : IEnumerable<HttpMediaTypeWithQualityHeaderValue>, IList<HttpMediaTypeWithQualityHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class HttpMediaTypeWithQualityHeaderValueCollection : IEnumerable<HttpMediaTypeWithQualityHeaderValue>, IList<HttpMediaTypeWithQualityHeaderValue>, IStringable
Public NotInheritable Class HttpMediaTypeWithQualityHeaderValueCollection
Implements IEnumerable(Of HttpMediaTypeWithQualityHeaderValue), IList(Of HttpMediaTypeWithQualityHeaderValue), IStringable
- 继承
- 属性
- 实现
Windows 要求
设备系列 |
Windows 10 (在 10.0.10240.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
示例
以下示例代码演示了一个方法,该方法使用 HttpMediaTypeWithQualityHeaderValueCollection 和 HttpMediaTypeWithQualityHeaderValue 类上的属性和方法获取和设置 HttpRequestMessage 对象上的 AcceptHTTP 标头。
using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;
public void DemonstrateHeaderRequestAccept()
{
var request = new HttpRequestMessage();
bool parsedOk = false;
// Set the header with a string.
parsedOk = request.Headers.Accept.TryParseAdd ("audio/*");
parsedOk = request.Headers.Accept.TryParseAdd ("audio/*; q=0.2");
parsedOk = request.Headers.Accept.TryParseAdd ("audio/*; q=0.4; mysetting=myvalue");
// Set the header with a strong type.
request.Headers.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("audio/*", .6));
// Get the strong type out
foreach (var value in request.Headers.Accept)
{
System.Diagnostics.Debug.WriteLine("One of the Accept values: {0}={1}", value.MediaType, value.Quality);
}
// The ToString() is useful for diagnostics, too.
System.Diagnostics.Debug.WriteLine("The Accept ToString() results: {0}", request.Headers.Accept.ToString());
}
注解
HttpMediaTypeWithQualityHeaderValueCollection 表示 HTTP 请求上的 Accept HTTP 标头的值。
HttpMediaTypeWithQualityHeaderValueCollection 是 HttpMediaTypeWithQualityHeaderValue 对象的集合,用于接受 HTTP Accept 标头中的信息。
HttpRequestHeaderCollection 上的 Accept 属性返回 HttpMediaTypeWithQualityHeaderValueCollection 对象。
属性
Size |
获取集合中 HttpMediaTypeWithQualityHeaderValue 对象的数目。 |