Newsgroups : Microsoft : microsoft.public.inetsdk.programming.wininet : 2006 Mar : InternetWriteFile Error 87
| Subject: | InternetWriteFile Error 87 |
| Posted by: | bdanie..@bisok.com |
| Date: | 29 Mar 2006 16:49:13 |
I just wanted to post that I have discovered a bug in the sample code
from MicroSoft that tells how to upload files to a web server using
wininet. The problem is that if the size of the file is an exact
multiple of the size of the buffer (e.g. 1024 bytes) then an Error 87
will occur on InternetWriteFile.
The reason this happens is that in the if a file size is the exact
multiple of the buffer size, then the loop will not be broken out of
after the last byte has been written. Instead, the code will attempt
to read another block. ReadFile will not return an error, but the
BytesRead counter will be set to zero. When this 0 value is passed to
InternetWriteFile in the dwNumberOfBytesToWrite parameter, the Error 87
(parameter is invalid) occurs.
To demonstrate the bug, create a file of exactly 1024 bytes and use the
sample code to transfer it over IIS. The Error 87 will occur every
time.
Perhaps this bug was already known but I have found no reference to it
anywhere, and this information may be useful.