FILE: Using HttpSendRequestEx for Large POST Requests

Last reviewed: January 19, 1998
Article ID: Q177188
The information in this article applies to:
  • Internet Client SDK, versions 4.0, 4.01
  • Internet Explorer (Programming), versions 4.0 4.01

SUMMARY

This sample demonstrates proper usage of the HttpSendRequestEx function introduced in the Internet Explorer 4.0 WinInet.dll and documented in the Internet Client SDK.

The original HttpSendRequest function has a significant limitation: all the data for the request has to be provided in a single buffer when the function is called. This is often inconvenient, leads to poor performance in certain client applications, and may make it impossible to upload large amounts of data from client machines with limited memory. The new HttpSendRequestEx function allows a program to start a request, send out the data in small pieces as available, then end the request once all the data has been sent. Internet Explorer 4.0 must be installed on the computer in order for this function to work.

The following file is available for download from the Microsoft Software Library:

 ~ Hsrex.exe (size: 25380 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

MORE INFORMATION

Hsrex.exe is a self-extracting archive that contains BigPost.cpp (the code for the demonstration program) and Readall.asp, an Active Server Pages (ASP) script that will read all data sent in a POST request. Readall.asp is provided as a sample target for BigPost, which can be used on Microsoft Internet Information Server (IIS) versions that support ASP. For other Web servers, you will need to provide a corresponding server script to read the data.

To compile the program with Microsoft Visual C++ 5.0, follow these steps:

  1. Run Visual C++ and create a new Win32 Console Application called "BigPost."

  2. In the directory where the project was created, run Hsrex.exe.

  3. Add BigPost.cpp to the BigPost project.

  4. Go to the Project Settings dialog box, click the Link tab, and add WinInet.lib to the "Object/library modules:" field.

  5. Ensure that Visual C++ is configured so that the compiler and linker will use the Wininet.h and Wininet.lib from the Internet Client SDK. If this is not done, a compiler or linker error will result. The include and library files included in Visual C++ do not contain the prototype and export of HttpSendRequestEx.

  6. Build the project. It will create BigPost.exe.

The program is run as follows:

   BigPost <Size> <Server> <Path>

For example, the following would POST 1 megabyte (1024KB) to http://yourserver/scripts/ReadAll.asp:

   BigPost 1024 yourserver /scripts/ReadAll.asp

The output from this would be as follows:

   Test of POSTing 1024KB with WinInet
   1048576 bytes sent.
   The following was returned by the server:
   1048576 bytes were read.

   Finished.

Notes

  • When using HttpSendRequestEx, the flag INTERNET_FLAG_NO_CACHE_WRITE should be used in the call to HttpOpenRequest, as shown in the following line from BigPost.cpp:

          HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", argv[3], NULL,
    
             NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
    
    
  • The functionality demonstrated in this sample represents the full implementation of HttpSendRequestEx at this time. The other flags and parameters present in the documentation for this function are not yet implemented.
  • Even though the data can be sent in multiple buffers of whatever sizes are convenient to the programmer, the total number of bytes that will be sent in the request must be known before the request is begun, and the total number of bytes that are actually sent must match this number exactly, or an error will be returned by HttpEndRequest.

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q177190
   TITLE     : BUG: Error 12019 When Calling InternetWriteFile

Keywords          : AXSDKMisc
Technology        : kbInetDev
Version           : WINDOWS:4.0
Platform          : WINDOWS
Issue type        : kbfile
Solution Type     : kbsample


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 19, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.