CHttpFile::SendRequest() error 
Author Message
 CHttpFile::SendRequest() error

I'm getting a failure (CInternetException) "server returned an invalid
response" on a send request call following a Open(POST) request.  I'm
trying to update data in a form which takes a file as input and submit
so that the file gets processed. One additional twist is that this is a
secure site. (I've taken care of the user/password authentication -
that works)
With my limited understanding, what I'm trying to do is basically,
1. Create and Internet Session
2. OpenRequest with POST as the verb
3. SendRequest with a header that specifies the Content-type as
4. SendRequestEX specifying the INTERNETBUFFER with the length of the
file, and doing repeat Writes of 1024 bytes each time till the end of
file is reached.
5. EndREquest.

Sounds pretty straightforward unless I'm missing something here. The
two errors I get are:
1. The aforementioned SendRequest error.("server returned an invalid
2. The first write of 1024 bytes seems to work fine, but the second
time around it throws an exception.

If anyone has done this before or knows what the problem could be, do
respond.  Thank you in advance.

The code:
  CString strHeaders =
  _T("ENCTYPE: multipart/form-data");
  CString strFormData = _T("file=c: \\temp\\NL09908031015.rst");

  pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,
BOOL result = pFile->SendRequest(strHeaders, LPVOID)
                 (LPCTSTR)strFormData, strFormData.GetLength());

  CFile srcfile;
  UINT nbytes;

  if (srcfile.Open("c:\\temp\\NL09908031015.rst", CFile::modeRead))

  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 = NULL;
  BufferIn.dwBufferLength = 0;
  BufferIn.dwBufferTotal = srcfile.GetLength() + 10; // This is the
only member used other than dwStructSize
  BufferIn.dwOffsetLow = 0;
  BufferIn.dwOffsetHigh = 0;

  pFile->SendRequestEx(&BufferIn, NULL, 0, 0);

  while ((nbytes = srcfile.Read(sz, 1023)) > 0)
    pFile->Write(sz, nbytes);  ***FAILS** second time around

Sent via http://www.*-*-*.com/
Share what you know. Learn what you don't.

Sat, 26 Jan 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. CHttpFile.SendRequest() Hangs Under Stress

2. POST form data to an ASP page using the CHttpFile member SendRequest

3. CHttpFile.SendRequest() Hangs Under Stress

4. Memory Management w/CHttpFile::SendRequest and ReadString

5. abort CHttpFile::SendRequest

6. Help me for function CHttpFile::SendRequest()

7. CHttpFile::SendRequest Authorization Problem

8. CHttpFile::SendRequest() doesn't return the control!

9. Error in CHttpFile ..

10. Error in CHttpFile ..

11. CHTTPFile Error

12. How to get the URL after SendRequest(...) using CHttpFile


Powered by phpBB® Forum Software