HttpBufferContent HttpBufferContent HttpBufferContent HttpBufferContent Class

Definition

Provides HTTP content that uses a buffer.

public : sealed class HttpBufferContent : IClosable, IStringable, IHttpContent
public sealed class HttpBufferContent : IDisposable, IStringable, IHttpContent
Public NotInheritable Class HttpBufferContent Implements IDisposable, IStringable, IHttpContent
var httpBufferContent = new httpBufferContent(content);
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

When sending (POST method) an HttpBufferContent class, the HttpProgress.BytesSent value jumps from 0% bytes sent to 100% bytes sent in one progress event, because the whole buffer is moved to lower network APIs all at once. For more detailed progress, use HttpStreamContent instead of HttpBufferContent, because streams are read and sent in smaller chunks, resulting in more progress events. E.g. 0 bytes sent, 65536 bytes sent, 131072 bytes sent, etc.

Constructors

HttpBufferContent(IBuffer) HttpBufferContent(IBuffer) HttpBufferContent(IBuffer) HttpBufferContent(IBuffer)

Initializes a new instance of the HttpBufferContent class with the specified buffer.

public : HttpBufferContent(IBuffer content)
public HttpBufferContent(IBuffer content)
Public Sub New(content As IBuffer)
var httpBufferContent = new httpBufferContent(content);
Parameters
content
IBuffer IBuffer IBuffer IBuffer

The content used to initialize the HttpBufferContent.

Remarks

The entire buffer specified in the content parameter is used to initialize the HttpBufferContent.

Below are the exceptions that this function throws.

E_INVALIDARG

The content parameter is null (Nothing in Visual Basic).

See Also

HttpBufferContent(IBuffer, UInt32, UInt32) HttpBufferContent(IBuffer, UInt32, UInt32) HttpBufferContent(IBuffer, UInt32, UInt32) HttpBufferContent(IBuffer, UInt32, UInt32)

Initializes a new instance of the HttpBufferContent class with an offset and count of bytes from the specified buffer.

public : HttpBufferContent(IBuffer content, unsigned int offset, unsigned int count)
public HttpBufferContent(IBuffer content, UInt32 offset, UInt32 count)
Public Sub New(content As IBuffer, offset As UInt32, count As UInt32)
var httpBufferContent = new httpBufferContent(content, offset, count);
Parameters
content
IBuffer IBuffer IBuffer IBuffer

The content used to initialize the HttpBufferContent.

offset
unsigned int UInt32 UInt32 UInt32

The offset in bytes from the beginning of the content buffer to initialize the HttpBufferContent.

count
unsigned int UInt32 UInt32 UInt32

The count of bytes in the content buffer to initialize the HttpBufferContent.

Remarks

Only the range specified by the offset parameter and the count parameter is used to initialize the HttpBufferContent.

Below are the exceptions that this content throws.

E_INVALIDARG

The content parameter is null (Nothing in Visual Basic).

The offset parameter is less than zero.

The offset parameter is greater than the length of content specified by the content parameter.

The count parameter is less than zero or the count parameter is greater than the length of content specified by the count parameter minus the offset parameter.

See Also

Properties

Headers Headers Headers Headers

Get a collection of content headers set on the HttpBufferContent.

public : HttpContentHeaderCollection Headers { get; }
public HttpContentHeaderCollection Headers { get; }
Public ReadOnly Property Headers As HttpContentHeaderCollection
var httpContentHeaderCollection = httpBufferContent.headers;
See Also

Methods

BufferAllAsync() BufferAllAsync() BufferAllAsync() BufferAllAsync()

Serialize the HttpBufferContent into memory as an asynchronous operation.

public : IAsyncOperationWithProgress<ulong, ulong> BufferAllAsync()
public IAsyncOperationWithProgress<ulong, ulong> BufferAllAsync()
Public Function BufferAllAsync() As IAsyncOperationWithProgress( Of ulong )( Of ulong )
var iAsyncOperationWithProgress = httpBufferContent.bufferAllAsync();
Returns

Remarks

This operation will not block. The returned IAsyncOperationWithProgress(UInt64, UInt64) object will complete after all of the content has been written into memory.

Close() Close() Close() Close()

Closes the HttpBufferContent instance and releases allocated resources.

public : void Close()
This member is not implemented in C#
This member is not implemented in VB.Net
httpBufferContent.close();

Remarks

The Close method releases allocated resources used by the HttpBufferContent instance. The Close method can manage the lifetime of system resources (memory for the HttpBufferContent, for example) used by a Windows Runtime object.

In the .NET Framework 4.5, this method projects as the Dispose method. In C++ and CX, this method projects as the destructor (delete operator).

Apps written in JavaScript, C#, or VB.NET use garbage collection to release resources. So the HttpBufferContent object and associated resources doesn't get released until the garbage collection pass runs. The Close method allows an app to release these resources early rather than waiting for the object to be released by garbage collection.

Apps written in C++ or CX don't have a Close method since these apps can destroy the object. In C++ and CX, objects are released when they fall out of program scope or as part of the destructor (delete operator) for the object.

Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

This member is not implemented in C++
void Dispose()
Sub Dispose
void Dispose()

ReadAsBufferAsync() ReadAsBufferAsync() ReadAsBufferAsync() ReadAsBufferAsync()

Serialize the HttpBufferContent to a buffer as an asynchronous operation.

public : IAsyncOperationWithProgress<IBuffer, ulong> ReadAsBufferAsync()
public IAsyncOperationWithProgress<IBuffer, ulong> ReadAsBufferAsync()
Public Function ReadAsBufferAsync() As IAsyncOperationWithProgress( Of IBuffer )( Of ulong )
var iAsyncOperationWithProgress = httpBufferContent.readAsBufferAsync();
Returns

Remarks

This operation will not block. The returned IAsyncOperationWithProgress(IBuffer, UInt64) object will complete after all of the content has been written to the buffer.

ReadAsInputStreamAsync() ReadAsInputStreamAsync() ReadAsInputStreamAsync() ReadAsInputStreamAsync()

Serialize the HttpBufferContent and return an input stream that represents the content as an asynchronous operation.

public : IAsyncOperationWithProgress<IInputStream, ulong> ReadAsInputStreamAsync()
public IAsyncOperationWithProgress<IInputStream, ulong> ReadAsInputStreamAsync()
Public Function ReadAsInputStreamAsync() As IAsyncOperationWithProgress( Of IInputStream )( Of ulong )
var iAsyncOperationWithProgress = httpBufferContent.readAsInputStreamAsync();
Returns

Remarks

This operation will not block. The returned IAsyncOperationWithProgress(IInputStream, UInt64) object will complete after all of the content has been written to the stream.

ReadAsStringAsync() ReadAsStringAsync() ReadAsStringAsync() ReadAsStringAsync()

Serialize the HttpBufferContent to a String as an asynchronous operation.

public : IAsyncOperationWithProgress<Platform::String, ulong> ReadAsStringAsync()
public IAsyncOperationWithProgress<string, ulong> ReadAsStringAsync()
Public Function ReadAsStringAsync() As IAsyncOperationWithProgress( Of string )( Of ulong )
var iAsyncOperationWithProgress = httpBufferContent.readAsStringAsync();
Returns

The object that represents the asynchronous operation.

Remarks

This operation will not block. The returned IAsyncOperationWithProgress(String, UInt64) object will complete after all of the content has been written to the String.

ToString() ToString() ToString() ToString()

Returns a string that represents the current HttpBufferContent object.

public : Platform::String ToString()
public string ToString()
Public Function ToString() As string
var string = httpBufferContent.toString();
Returns
Platform::String string string string

A string that represents the current object.

TryComputeLength(UInt64) TryComputeLength(UInt64) TryComputeLength(UInt64) TryComputeLength(UInt64)

Computes the HttpBufferContent length in bytes.

public : Platform::Boolean TryComputeLength(unsigned __int64 length)
public bool TryComputeLength(UInt64 length)
Public Function TryComputeLength(length As UInt64) As bool
var bool = httpBufferContent.tryComputeLength(length);
Parameters
length
unsigned __int64 UInt64 UInt64 UInt64

The length in bytes of the HttpBufferContent.

Returns
Platform::Boolean bool bool bool

true if length is a valid length; otherwise, false.

Remarks

The TryComputeLength method calculates the content length for the HttpBufferContent. This is useful for content types that are easy to calculate the content length.

WriteToStreamAsync(IOutputStream) WriteToStreamAsync(IOutputStream) WriteToStreamAsync(IOutputStream) WriteToStreamAsync(IOutputStream)

Write the HttpBufferContent to an output stream as an asynchronous operation.

public : IAsyncOperationWithProgress<ulong, ulong> WriteToStreamAsync(IOutputStream outputStream)
public IAsyncOperationWithProgress<ulong, ulong> WriteToStreamAsync(IOutputStream outputStream)
Public Function WriteToStreamAsync(outputStream As IOutputStream) As IAsyncOperationWithProgress( Of ulong )( Of ulong )
var iAsyncOperationWithProgress = httpBufferContent.writeToStreamAsync(outputStream);
Parameters
outputStream
IOutputStream IOutputStream IOutputStream IOutputStream

The output stream to write to.

Returns

Remarks

This operation will not block. The returned IAsyncOperationWithProgress(UInt64, UInt64) object will complete after all of the content has been written to the output stream.