共用方式為


Connecting to web services (XAML)

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Purpose

These topics demonstrate a variety of ways to connect your app to a web service. The default choice is to use Windows.Web.Http.HttpClient, a new Windows Runtime class which is available for all languages. Apps that use C++ and XAML can also use the C++ REST SDK to create reusable code that will run in desktop applications or apps on downlevel editions of Windows as well as Linux. C++ apps that only target Windows 8, and desktop applications that target Windows 8 and later, can also use the IXMLHttpRequest2 COM interface.

The following table summarizes which API is supported on which platform (* = not recommended for apps).

API Languages Platform

Windows.Web.Http.HttpClient

C#, Visual Basic, C++ Windows 8.1, Windows Server 2012 R2, Windows Phone 8.1

System.Net.Http.HttpClient

C#, Visual Basic Windows 8.1*, Windows Server 2012 R2*, Windows 8, Windows Server 2012, Windows 7 SP1, Windows Server 2008 R2 SP1, Windows Server 2008 SP 2, Windows Vista SP 2
XML HTTP Extended Request (IXMLHttpRequest2) C++ Windows 8.1*, Windows Server 2012 R2*,Windows 8, Windows Server 2012

C++ REST SDK

C++ Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7 SP 1, Windows Server 2008 R2 SP1, Windows Server 2008 SP 2, Windows Vista SP 2, Linux

 

In this section

Topic Description

How to connect to an HTTP server using Windows.Web.Http

Send a GET request to a web service and retrieve the response using the Windows.Web.Http.HttpClient class in the Windows.Web.Http namespace.

How to connect using XML HTTP Request and IXMLHTTPRequest2

Use XML HTTP Extended Request and the IXMLHTTPRequest2 interface to send HTTP GET and POST requests to a web service using C++ in a Windows Runtime app.

How to connect to Bing Maps using Windows::Web::Http:HttpClient

Connect to Bing Maps using the Windows::Web::Http::HttpClient class in the Windows::Web::Http::HttpClient namespace.

How to connect to Bing Maps using the C++ REST SDK

Use the C++ REST SDK to connect to Bing Maps using C++ in a Windows Store app.

Connecting to an HTTP server using System.Net.Http.HttpClient

Use System.Net.Http.HttpClient to connect to a web service using C# or Visual Basic in a Windows Store app.

 

Developer audience

Developers using VB/C#/C++ and XAML interested in creating Windows Runtime apps that connect to a web service.

The following information applies to Windows Runtime apps written in C++/XAML and apps using the .NET Framework 4.5 in C# or Visual Basic.

For more information on how to connect to a web service for Windows Runtime apps written in JavaScript and HTML, see Connecting to a web service Windows Runtime app using JavaScript.

Other resources

Adding support for networking

Connecting to web services Windows Runtime app using JavaScript

How to configure network capabilities

How to set background connectivity options

Troubleshoot and debug network connections

Reference

IXMLHTTPRequest2 interface

System.Net.Http

System.Net.Http.Headers

System.Net.Http.HttpClient

Windows.Web.Http

Windows.Web.Http.Filters

Windows.Web.Http.Headers

Windows.Web.Http.HttpClient

XML HTTP Extended Request (IXMLHttpRequest2)

Samples

ControlChannelTrigger HttpClient sample

HttpClient Sample

Windows authentication broker sample

XML HTTP Request 2 GET sample

XML HTTP Request 2 POST sample