Http​String​Content Http​String​Content Http​String​Content Class

Definition

Provides HTTP content that uses a string.

public sealed class HttpStringContent : IClosable, IStringable, IHttpContentpublic sealed class HttpStringContent : IDisposable, IStringable, IHttpContentPublic NotInheritable Class HttpStringContent Implements IDisposable, IStringable, IHttpContent
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Constructors

HttpStringContent(String) HttpStringContent(String) HttpStringContent(String)

Initializes a new instance of the HttpStringContent class with the specified content.

public HttpStringContent(String content)public HttpStringContent(String content)Public Sub New(content As String)
Parameters
content
System.String System.String System.String

The content used to initialize the HttpStringContent.

Attributes

Remarks

The media type in the Content-Type header for the HttpStringContent created defaults to text/plain.

HttpStringContent(String, UnicodeEncoding) HttpStringContent(String, UnicodeEncoding) HttpStringContent(String, UnicodeEncoding)

Initializes a new instance of the HttpStringContent class with the specified content and encoding.

public HttpStringContent(String content, UnicodeEncoding encoding)public HttpStringContent(String content, UnicodeEncoding encoding)Public Sub New(content As String, encoding As UnicodeEncoding)
Parameters
content
System.String System.String System.String

The content used to initialize the HttpStringContent.

encoding
UnicodeEncoding UnicodeEncoding UnicodeEncoding

The encoding to use for the content.

Attributes

Remarks

The media type in the Content-Type header for the HttpStringContent created defaults to text/plain.

HttpStringContent(String, UnicodeEncoding, String) HttpStringContent(String, UnicodeEncoding, String) HttpStringContent(String, UnicodeEncoding, String)

Initializes a new instance of the HttpStringContent class with the specified content, encoding, and media type.

public HttpStringContent(String content, UnicodeEncoding encoding, String mediaType)public HttpStringContent(String content, UnicodeEncoding encoding, String mediaType)Public Sub New(content As String, encoding As UnicodeEncoding, mediaType As String)
Parameters
content
System.String System.String System.String

The content used to initialize the HttpStringContent.

encoding
UnicodeEncoding UnicodeEncoding UnicodeEncoding

The encoding to use for the content.

mediaType
System.String System.String System.String

The media type to use for the content.

Attributes

Remarks

The media type in the Content-Type header for the HttpStringContent created is set to the value of the mediaType parameter.

Properties

Headers Headers Headers

Get a collection of content headers set on the HttpStringContent.

public HttpContentHeaderCollection Headers { get; }public HttpContentHeaderCollection Headers { get; }Public ReadOnly Property Headers As HttpContentHeaderCollection
Attributes

Methods

BufferAllAsync() BufferAllAsync() BufferAllAsync()

Serialize the HttpStringContent into memory as an asynchronous operation.

public IAsyncOperationWithProgress<ulong, ulong> BufferAllAsync()public IAsyncOperationWithProgress<ulong, ulong> BufferAllAsync()Public Function BufferAllAsync() As IAsyncOperationWithProgress( Of ulong, ulong )
Returns

The object that represents the asynchronous operation.

Attributes

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()

Closes the HttpStringContent instance and releases allocated resources.

public void Close()This member is not implemented in C#This member is not implemented in VB.Net
Attributes

Remarks

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

In the .NET Framework 4.5, this method projects as the Dispose method. In Visual C++ component extensions (C++/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 HttpStringContent 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()

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

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

ReadAsBufferAsync() ReadAsBufferAsync() ReadAsBufferAsync()

Serialize the HttpStringContent to a buffer as an asynchronous operation.

public IAsyncOperationWithProgress<IBuffer, ulong> ReadAsBufferAsync()public IAsyncOperationWithProgress<IBuffer, ulong> ReadAsBufferAsync()Public Function ReadAsBufferAsync() As IAsyncOperationWithProgress( Of IBuffer, ulong )
Returns

The object that represents the asynchronous operation.

Attributes

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()

Serialize the HttpStringContent 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, ulong )
Returns

The object that represents the asynchronous operation.

Attributes

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()

Serialize the HttpStringContent to a String as an asynchronous operation.

public IAsyncOperationWithProgress<string, ulong> ReadAsStringAsync()public IAsyncOperationWithProgress<string, ulong> ReadAsStringAsync()Public Function ReadAsStringAsync() As IAsyncOperationWithProgress( Of string, ulong )
Returns

The object that represents the asynchronous operation.

Attributes

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()

Returns a string that represents the current HttpStringContent object.

public string ToString()public string ToString()Public Function ToString() As string
Returns
string string string

A string that represents the current object.

Attributes

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

Compute the HttpStringContent length in bytes.

public bool TryComputeLength(UInt64 length)public bool TryComputeLength(UInt64 length)Public Function TryComputeLength(length As UInt64) As bool
Parameters
length
System.UInt64 System.UInt64 System.UInt64

The length in bytes of the HttpStringContent.

Returns
bool bool bool

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

The return value should never be false.

Attributes

Remarks

The TryComputeLength method calculates the content length for HTTP content in HttpStringContent. Headers set on the content are not included in the content length. This is useful for content types that are easy to calculate the content length.

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

Write the HttpStringContent 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, ulong )
Parameters
outputStream
IOutputStream IOutputStream IOutputStream

The output stream to write to.

Returns

The object that represents the asynchronous operation.

Attributes

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.