Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

SAMPLE: SendRequestExAsync Uses HttpSendRequestEx Asynchronously

View products that this article applies to.

This article was previously published under Q242019

↑ Back to the top


Although you can use HttpSendRequestEx to post large amounts of data both synchronously and asynchronously, using HttpSendRequestEx asynchronously can be a difficult task due to a number of issues involved in the timing and use of the various WinInet calls.

The sample SendRequestExAsync.cpp included in this article demonstrates how to properly call HttpSendRequestEx in an asynchronous WinInet application. You can compile and run SendRequestExAsync.cpp to send a large HTTP request to a server.

↑ Back to the top

More information

When you try to use HttpSendRequestEx and other associated APIs asynchronously, you need to be aware of the following issues:
  • All the normal issues that apply to standard asynchronous WinInet applications also apply when you use HttpSendRequestEx synchronously. For additional information on how to use WinInet APIs asynchronously, as well as sample code and a list of issues that are common to all asynchronous WinInet applications, click the article number below to view the article in the Microsoft Knowledge Base:
    275046� SAMPLE: Using AsyncHTTP to Call WinInet APIs Asynchronously
  • You will receive the completion for HttpSendRequestEx when all HTTP request headers have been successfully sent.

  • You will receive the completion for HttpEndRequest when all HTTP response headers are received from the server.

  • You cannot call InternetReadFile(Ex) until you receive a successful completion of HttpEndRequest. Therefore, you must wait until you get an INTERNET_STATUS_REQUEST_COMPLETE notification for HttpEndRequest before you can call InternetReadFile(Ex).

  • Even though your request handle has been opened with the asynchronous flag, InternetWriteFile tends to immediately return, indicating that the data has been sent successfully. This is because the operation that sends data across the underlying socket returns as soon as the data has entered the protocol's buffers. This is a very fast operation. Therefore, it completes before InternetWriteFile has a chance to return. However, if you repeatedly call InternetWriteFile too quickly or if you specify a particularly large buffer, you will eventually see it return ERROR_IO_PENDING. Only if you get an ERROR_IO_PENDING return will you receive an INTERNET_STATUS_REQUEST_COMPLETE notification for your call to InternetWriteFile.

The following file is available for download from the Microsoft Download Center:
Release Date: Jan-24-2002

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591� How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The SendRequestExAsync.exe file contains the following files:

Collapse this tableExpand this table
File name

↑ Back to the top


For additional information about using HttpSendRequestEx, click the article number below to view the article in the Microsoft Knowledge Base:
177188� FILE: Using HttpSendRequestEx for Large Post Requests

↑ Back to the top

Keywords: KB242019, kbhttp, kbhowto, kbfile

↑ Back to the top

Article Info
Article ID : 242019
Revision : 4
Created on : 8/5/2004
Published on : 8/5/2004
Exists online : False
Views : 421