我通过HttpSendRequest(hRequest, hdrs, strlen(hdrs), postdata, strlen(postdata))将一块数据提交给CGI,如果postdata比较小的话没有问题,可是当我的postdata比较大,比如几十k的时候服务器就会报如下的错:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
Size of a request header field exceeds server limit.<P>


请问如何解决

解决方案 »

  1.   

    FROM MSDN:
    Please note that HttpSendRequest can be used only with a single buffer of limited size. HttpSendRequestEx and InternetWriteFile can be used to send buffers of any size as follows: BOOL UseHttpSendReqEx(HINTERNET hConnect, TCHAR *upFile)
       {
         INTERNET_BUFFERS BufferIn = {0};
         DWORD dwBytesRead;
         DWORD dwBytesWritten;
         BYTE pBuffer[1024]; // Read from file in 1K chunks
         BOOL bRead, bRet;     BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );     HINTERNET hRequest = HttpOpenRequest (hConnect, "PUT",
             "/test/page.htm", NULL, NULL, NULL,  0, 0);
         if (!hRequest)
         {
           printf("Failed to open request handle: %lu\n", GetLastError ());
           return FALSE;
         }     HANDLE hFile = CreateFile (upFile, GENERIC_READ, FILE_SHARE_READ,
             NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
         if (hFile == INVALID_HANDLE_VALUE)
         {
           printf("\nFailed to open local file %s.", upFile);
           return FALSE;
         }     BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
         printf ("File size is %d\n", BufferIn.dwBufferTotal );     if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE, 0))
         {
           printf( "Error on HttpSendRequestEx %lu\n",GetLastError() );
           return FALSE;
         }     DWORD sum = 0;
         do
         {
           if  (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer),
               &dwBytesRead, NULL)))
           {
             printf ("\nReadFile failed on buffer %lu.",GetLastError());
             break;
           }
           if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
               &dwBytesWritten)))
           {
             printf ("\nInternetWriteFile failed %lu", GetLastError());
             break;
           }
           sum += dwBytesWritten;
         }
         while (dwBytesRead == sizeof(pBuffer)) ;     CloseHandle (hFile);
         printf ("Actual written bytes: %d\n", sum);     if(!HttpEndRequest(hRequest, NULL, 0, 0))
         {
           printf( "Error on HttpEndRequest %lu \n", GetLastError());
           return FALSE;
         }
         return TRUE;
       }

      

  2.   

    HttpSendRequest只能发送小文件,大文件就不行了.发送大文件应该用HttpSendRequestEx
    楼主看看微软的例子http://support.microsoft.com/kb/177188/EN-US/