HttpContentHeaderCollection.ContentMD5 属性

定义

获取或设置 HTTP 内容上的 HTTP Content-MD5 标头的值。

public:
 property IBuffer ^ ContentMD5 { IBuffer ^ get(); void set(IBuffer ^ value); };
IBuffer ContentMD5();

void ContentMD5(IBuffer value);
public IBuffer ContentMD5 { get; set; }
var iBuffer = httpContentHeaderCollection.contentMD5;
httpContentHeaderCollection.contentMD5 = iBuffer;
Public Property ContentMD5 As IBuffer

属性值

HTTP 内容上的 HTTP Content-MD5 标头的值。 null 值表示标头不存在。

注解

下面的示例代码演示了使用 HttpContentHeaderCollection 对象上的 ContentMD5 属性获取或设置 HTTP 内容上的 Content-MD5 标头值的方法。

// Content-MD5 header
// IBuffer
void DemoContentMD5(IHttpContent content) {
    var h = content.Headers;

    var str = "This is my content string";
    var alg = Windows.Security.Cryptography.Core.HashAlgorithmProvider.OpenAlgorithm("MD5");
    var buff = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary(str, Windows.Security.Cryptography.BinaryStringEncoding.Utf8);
    var hashed = alg.HashData(buff);
    var res = Windows.Security.Cryptography.CryptographicBuffer.EncodeToHexString(hashed);
    h.ContentMD5 = hashed;

    var header = h.ContentMD5;
    uiLog.Text += "\nCONTENT MD5 HEADER\n";

    uiLog.Text += string.Format("ContentMD5: ToString: {0}\n\n", header.ToString());
    uiLog.Text += string.Format("ContentMD5: base64: {0} hex: {1}\n\n", Convert.ToBase64String(h.ContentMD5.ToArray()), res);
}

适用于