EN
Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

Windows.Web.Http namespace

Applies to Windows and Windows Phone

Provides a modern HTTP client API for Windows Store apps.

Members

The Windows.Web.Http namespace has these types of members:

Classes

The Windows.Web.Http namespace has these classes.

ClassDescription
HttpBufferContent Provides HTTP content that uses a buffer.
HttpClient Sends HTTP requests and receives HTTP responses from a resource identified by a URI.
HttpCookie Provides a set of properties and methods to manage an HTTP cookie.
HttpCookieCollection Provides a collection container for instances of the HttpCookie class.
HttpCookieManager Add or delete an HttpCookie or view the cookies associated with an app.
HttpFormUrlEncodedContent Provides HTTP content that uses name/value data encoded with the application/x-www-form-urlencoded MIME type.
HttpMethod Retrieves standard HTTP methods such as GET and POST and creates new HTTP methods.
HttpMultipartContent Provides HTTP content that uses the multipart/* MIME type.
HttpMultipartFormDataContent Provides HTTP content that uses the multipart/form-data MIME type.
HttpRequestMessage Represents an HTTP request message including headers.
HttpResponseMessage Represents an HTTP response message including headers, the status code, and data.
HttpStreamContent Provides HTTP content that uses a stream.
HttpStringContent Provides HTTP content that uses a string.
HttpTransportInformation Provides information about the underlying transport used by the HTTP connection.

 

Enumerations

The Windows.Web.Http namespace has these enumerations.

EnumerationDescription
HttpCompletionOption Indicates whether asynchronous HttpClient operations are considered completed when all of the response is read, or when just the headers are read.
HttpProgressStage Indicates the step in the progress for an HTTP connection.
HttpResponseMessageSource Indicates the source of the data received in the HttpResponseMessage.
HttpStatusCode Contains the values of status codes defined for HTTP in the response to an HTTP request.
HttpVersion Represents the HTTP protocol version.

 

Interfaces

The Windows.Web.Http namespace defines these interfaces.

InterfaceDescription
IHttpContent Provides a base interface for an HTTP entity body and content headers.

 

Structures

The Windows.Web.Http namespace has these structures.

StructureDescription
HttpProgress Contains status information on the progress of an HttpClient operation.

 

Remarks

The Windows.Web.Http namespace and the related Windows.Web.Http.Headers and Windows.Web.Http.Filters namespaces provide a programming interface for Windows Store apps that target HTTP and REST services. This features of this new HTTP API are designed to be in compliance with HTTP as defined in RFC 2616 by the IETF. The new HTTP API provides consistent support in JavaScript, C#, VB.NET, and C++ for developers.

This new API replaces the use of three different APIs with differing features that previously were needed for each language projection in Windows 8.

Classes in the Windows.Web.Http and related namespaces are targeted at all levels of HTTP and REST development:

  • Basic HTTP developers
  • Site-specific HTTP library developers
  • Advanced HTTP developers

For basic HTTP developers, the new API has a simple interface to handle the most common tasks and sensible defaults for authentication that should work in most environments. For library developers, the consistent object model and multiple language support means you can write a library once for developers in all languages. For advanced HTTP developers, the new API includes a rich set of capabilities.

The Windows.Web.Http namespace and the related namespaces provide these components:

The contents of an HTTP message corresponds to the entity body defined in RFC 2616. Several classes and an interface in the Windows.Web.Http namespace can be used for HTTP content, including:

  • IHttpContent - A base interface for developers to create their own content objects. It represents an HTTP entity body and content headers. This interface has methods that get and set the actual content data. It also provides properties that get and set content related headers.
  • HttpBufferContent - HTTP content that uses a buffer.
  • HttpFormUrlEncodedContent - HTTP content that uses name/value tuples encoded with the application/x-www-form-urlencoded MIME type.
  • HttpMultipartContent - HTTP content that uses multipart/* MIME type.
  • HttpMultipartFormDataContent - HTTP content that uses the encoded multipart/form-data MIME type.
  • HttpStreamContent - HTTP content that uses a stream. This content type is used by the HTTP GET method to receive data and the HTTP POST method to upload data.
  • HttpStringContent - HTTP content that uses a string.

Classes in the Windows.Web.Http.Headers namespace represent HTTP headers defined in RFC 2616. HTTP headers are associated with HttpRequestMessage and HttpResponseMessage as properties that are retrieved or set.

Classes in the Windows.Web.Http namespace can use filters based on the classes in the Windows.Web.Http.Filters namespace. Filters provide handlers to help with common HTTP service issues. Filters can be chained together in a sequence to address more complex HTTP service issues. Several ready-to-use filters are included with Windows 8.1 to help library developers fix common HTTP service issues. These filters include handlers for monitored network connections and retry. Library developers can write their own filters for site-specific issues (for example, a site might use the 503 (Server Unavailable) response to indicate the request should be retried).

If an app that uses the Windows.Web.Http namespace and the related Windows.Web.Http.Headers and Windows.Web.Http.Filters namespaces downloads large amounts of data (50 megabytes or more), then the app should stream those downloads and not use the default buffering. If the default buffering is used the client memory usage gets very large, potentially resulting in reduced performance.

For sample code in C#/VB/C++ and XAML that shows how to use HttpClient to connect to an HTTP server, see Connecting to an HTTP server using Windows.Web.Http.HttpClient (Windows Store apps using C#/VB/C++ and XAML).

For sample code in JavaScript and HTML that shows how to use HttpClient to connect to an HTTP server, see Connecting to an HTTP server using Windows.Web.Http(Windows Store apps using JavaScript and HTML).

Examples

The following sample code shows how to GET content from an HTTP server as a string.



// Note: the URI constructor will throw an exception
// if the string passed is not a valid URI
var uri = new Uri("http://example.com/datalist.aspx");
var httpClient = new HttpClient();

// Always catch network exceptions for async methods
httpClient.GetStringAsync(uri).done(function () {
        // get completed
    }, onError);


function onError(reason) {
    // Details in reason.Message and ex.HResult.       
}

// Once your app is done using the HttpClient object call close to 
// free up system resources (the underlying socket and memory used for the object)
// httpClient.close();


Requirements

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Web.Http
Windows::Web::Http [C++]

Metadata

Windows.winmd

See also

Other resources
Connecting to an HTTP server using Windows.Web.Http.HttpClient (Windows Store apps using C#/VB/C++ and XAML)
Connecting to an HTTP server using Windows.Web.Http(Windows Store apps using JavaScript and HTML)
Handling exceptions in network apps
Reference
System.Uri
Windows.Foundation.Uri
Windows.Web.Http
Windows.Web.Http.Filters
Windows.Web.Http.Headers
Samples
HttpClient Sample

 

 

Anzeigen:
© 2014 Microsoft. Alle Rechte vorbehalten.