HttpSendRequestEx发送大文件_第1页
HttpSendRequestEx发送大文件_第2页
HttpSendRequestEx发送大文件_第3页
HttpSendRequestEx发送大文件_第4页
HttpSendRequestEx发送大文件_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、SUMMARYThis 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 singl

2、e 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, sen

3、d 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 Download Center:Hsrex.exe ( For additional in

4、formation 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-

5、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.MORE INFORMATIONThe program is run as follows: BigPost <Size> <Server> <Path> For example, the follo

6、wing 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

7、· 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", argv3, NULL,· NULL, NULL, INTERNET_FLAG_NO_CACHE_WRI

8、TE, 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 what

9、ever 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.Back to the topBigPos

10、t.cpp#include <Windows.h>#include <WinINet.h>#include <stdio.h>BOOL UseHttpSendReqEx(HINTERNET hRequest, DWORD dwPostSize);#define BUFFSIZE 500void main( int argc, char *argv )DWORD dwPostSize;if (argc < 4)printf("Usage: Bigpost <Size> <Server> <Path>n&quo

11、t;);printf("<Size> is the number of KB to POSTn");printf("<Server> is the server to POST ton");printf("<Path> is the virtual path to POST ton");exit(0);if ( (dwPostSize = strtoul(argv1,NULL,10) = 0) | (dwPostSize >= 2047999) )printf("%s is inva

12、lid size. Valid sizes are from 1 to 2047999n", argv1);exit(0);printf( "Test of POSTing %luKB with WinInetn", dwPostSize);dwPostSize *= 1024; / Convert KB to bytesHINTERNET hSession = InternetOpen( "HttpSendRequestEx", INTERNET_OPEN_TYPE_PRECONFIG,NULL, NULL, 0);if(!hSession)

13、printf("Failed to open sessionn");exit(0);HINTERNET hConnect = InternetConnect(hSession, argv2, INTERNET_DEFAULT_HTTP_PORT,NULL, NULL, INTERNET_SERVICE_HTTP,NULL, NULL);if (!hConnect)printf( "Failed to connectn" );elseHINTERNET hRequest = HttpOpenRequest(hConnect, "POST"

14、;, argv3, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);if (!hRequest)printf( "Failed to open request handlen" );elseif(UseHttpSendReqEx(hRequest, dwPostSize)char pcBufferBUFFSIZE;DWORD dwBytesRead;printf("nThe following was returned by the server:n");dodwBytesRead=0;if(Inte

15、rnetReadFile(hRequest, pcBuffer, BUFFSIZE-1, &dwBytesRead)pcBufferdwBytesRead=0x00; / Null-terminate bufferprintf("%s", pcBuffer);elseprintf("nInternetReadFile failed");while(dwBytesRead>0);printf("n");if (!InternetCloseHandle(hRequest)printf( "Failed to clo

16、se Request handlen" );if(!InternetCloseHandle(hConnect)printf("Failed to close Connect handlen");if( InternetCloseHandle( hSession ) = FALSE )printf( "Failed to close Session handlen" );printf( "nFinished.n" );BOOL UseHttpSendReqEx(HINTERNET hRequest, DWORD dwPostS

17、ize)INTERNET_BUFFERS BufferIn;DWORD dwBytesWritten;int n;BYTE pBuffer1024;BOOL bRet;BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS ); / Must be set or error will occur BufferIn.Next = NULL; BufferIn.lpcszHeader = NULL; BufferIn.dwHeadersLength = 0; BufferIn.dwHeadersTotal = 0; BufferIn.lpvBuffer =

18、 NULL; BufferIn.dwBufferLength = 0; BufferIn.dwBufferTotal = dwPostSize; / This is the only member used other than dwStructSize BufferIn.dwOffsetLow = 0; BufferIn.dwOffsetHigh = 0; if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, 0, 0) printf( "Error on HttpSendRequestEx %dn",GetLastE

19、rror() ); return FALSE; FillMemory(pBuffer, 1024, 'D'); / Fill buffer with databRet=TRUE;for(n=1; n<=(int)dwPostSize/1024 && bRet; n+)if(bRet=InternetWriteFile( hRequest, pBuffer, 1024, &dwBytesWritten)printf( "r%d bytes sent.", n*1024);if(!bRet) printf( "nError on InternetWriteFile %lun",GetLastError() ); return FALSE; if(!HttpEndRequest(hRequest, NULL, 0, 0) printf( "Error on HttpEndRequest %lu n", GetLastError(); return FA

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论