Dela via


HttpContentHeaderCollection.ContentMD5 Property

Definition

Gets or sets the value of an HTTP Content-MD5 header on the HTTP content.

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

Property Value

The value of the HTTP Content-MD5 header on the HTTP content. A null value means that the header is absent.

Remarks

The following sample code shows a method to get or set the Content-MD5 header value on HTTP content using the ContentMD5 property on the HttpContentHeaderCollection object.

// 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);
}

Applies to