SAMPLE: SendRequestExAsync Uses HttpSendRequestEx Asynchronously (242019)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.5
  • Microsoft Windows Internet Services (WinInet)

This article was previously published under Q242019

SUMMARY

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.

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:

File name
SendRequestAsync.cpp
SendRequestAsync.dsp

REFERENCES

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


Modification Type:MinorLast Reviewed:8/5/2004
Keywords:kbfile kbhowto kbhttp KB242019