Export (0) Print
Expand All

HttpClient Sample: HTTP Client Services Demonstration 

Download sample

Demonstrates making HTTP Web requests from within an MFC application using ATL Server's HTTP client support.

The HttpClient sample is an MFC dialog box application that allows users to retrieve and examine an HTTP response from a given URL. The HttpClient sample uses the CAtlHttpClientT class, which simplifies HTTP client operations by providing a simple interface and handling redirections and protection schemes in an automated fashion. After a successful HTTP transaction, the sample displays the response headers and body. If the URL indicates an image, the sample displays the image in a separate dialog box.

This sample demonstrates:

  • Using the CAtlHttpClientT class to launch HTTP client requests and receive responses.

  • Using the CAtlNavigateData class to modify the default CAtlHttpClientT behavior, including installing a callback that is called periodically during large downloads. The sample uses this callback to update a progress bar.

  • Using the CAtlHttpClientT::SetProxy function to direct HTTP transactions to be performed through a proxy server.

  • Optional use of the CBasicAuthObject and CNTLMAuthObject classes to allow access to protected URLs.

  • Using the ATL CImage class to display image data, if the URL provided by the user points to an image file.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Requirements

  • IIS

Building and Running the Sample

To build and run this sample

  1. Open the solution file, HttpClient.sln, in the Visual Studio development environment.

  2. Build the solution.

  3. From the Debug menu, click Start.

  4. Enter a URL in the URL text box, specify proxy server settings if necessary, and click the Navigate button. The sample will make an HTTP GET request to the specified URL and display the resulting response data or an error message. If the server returns an image, the sample will display the image in a separate window.

Demonstrates

See Also

Community Additions

ADD
Show:
© 2014 Microsoft