glenn
2005-07-06 16:16:09 UTC
I need to upload files to an http server using multipart/form-data.
Copying from a browser reply to a form page, this seems to be the
example of what should be sent (caught with mozilla and live headers.)
POST /cgi-bin/upload-cgi.pl HTTP/1.1
... other headers snipped ...
Content-Type: multipart/form-data; boundary=19024605111143684786787635207
Content-Length: 497
--19024605111143684786787635207
Content-Disposition: form-data; name="info"
this is some info
--19024605111143684786787635207
Content-Disposition: form-data; name="file"; filename="afile"
Content-Type: application/octet-stream
hello, this is a small one line file
--19024605111143684786787635207
The above is well and good, it matches the RFC etc my problem is in getting
WinHTTP to do the above. I can set up the connection etc... get the needed
handles, and add the headers that I want but all that I seem to be able to
make work is this: (from the winhttp trace tool)
09:24:30.519 ::*0000001* :: <<<<-------- HTTP stream follows below
----------->>>>
09:24:30.519 ::*0000001* :: POST /cgi-bin/upload-cgi.pl HTTP/1.1
09:24:30.519 ::*0000001* :: Content-Type: multipart/form-data;
boundary=127651370705190000
09:24:30.519 ::*0000001* :: Content-Disposition: form-data; name="info"
09:24:30.519 ::*0000001* :: Content-Disposition: form-data; name="file";
filename="junk.dat"
09:24:30.519 ::*0000001* :: Content-Type: application/octet-stream
09:24:30.519 ::*0000001* :: User-Agent: WebStream Service
09:24:30.519 ::*0000001* :: Host: 10.0.0.199
09:24:30.519 ::*0000001* :: Content-Length: 689
09:24:30.519 ::*0000001* :: Connection: Keep-Alive
09:24:30.519 ::*0000001* ::
09:24:30.519 ::*0000001* ::
09:24:30.519 ::*0000001* :: <<<<-------- End
--------------------------------->>>>
and the file data
09:24:30.519 ::*0000001* :: <<<<-------- HTTP stream follows below
----------->>>>
09:24:30.519 ::*0000001* :: 0 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 1 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 2 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 3 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 4 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 5 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 6 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 7 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 8 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 9 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* ::
09:24:30.519 ::*0000001* :: <<<<-------- End
--------------------------------->>>>
Whenever I try to insert the text for the info field or a boundary line the
winhttp
coughs up an error. The examples are way too simple and the docs are mute
on this problem. If you can't insert boundary lines nor the intermediate
field data it seems that it is impossible to generate a valid
multipart/form-data POST using winhttp.
Is this the case for the current version of the winhttp library?
Copying from a browser reply to a form page, this seems to be the
example of what should be sent (caught with mozilla and live headers.)
POST /cgi-bin/upload-cgi.pl HTTP/1.1
... other headers snipped ...
Content-Type: multipart/form-data; boundary=19024605111143684786787635207
Content-Length: 497
--19024605111143684786787635207
Content-Disposition: form-data; name="info"
this is some info
--19024605111143684786787635207
Content-Disposition: form-data; name="file"; filename="afile"
Content-Type: application/octet-stream
hello, this is a small one line file
--19024605111143684786787635207
The above is well and good, it matches the RFC etc my problem is in getting
WinHTTP to do the above. I can set up the connection etc... get the needed
handles, and add the headers that I want but all that I seem to be able to
make work is this: (from the winhttp trace tool)
09:24:30.519 ::*0000001* :: <<<<-------- HTTP stream follows below
----------->>>>
09:24:30.519 ::*0000001* :: POST /cgi-bin/upload-cgi.pl HTTP/1.1
09:24:30.519 ::*0000001* :: Content-Type: multipart/form-data;
boundary=127651370705190000
09:24:30.519 ::*0000001* :: Content-Disposition: form-data; name="info"
09:24:30.519 ::*0000001* :: Content-Disposition: form-data; name="file";
filename="junk.dat"
09:24:30.519 ::*0000001* :: Content-Type: application/octet-stream
09:24:30.519 ::*0000001* :: User-Agent: WebStream Service
09:24:30.519 ::*0000001* :: Host: 10.0.0.199
09:24:30.519 ::*0000001* :: Content-Length: 689
09:24:30.519 ::*0000001* :: Connection: Keep-Alive
09:24:30.519 ::*0000001* ::
09:24:30.519 ::*0000001* ::
09:24:30.519 ::*0000001* :: <<<<-------- End
--------------------------------->>>>
and the file data
09:24:30.519 ::*0000001* :: <<<<-------- HTTP stream follows below
----------->>>>
09:24:30.519 ::*0000001* :: 0 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 1 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 2 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 3 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 4 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 5 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 6 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 7 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 8 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* :: 9 junk.dat 0123456789 0123456789 0123456789
09:24:30.519 ::*0000001* ::
09:24:30.519 ::*0000001* :: <<<<-------- End
--------------------------------->>>>
Whenever I try to insert the text for the info field or a boundary line the
winhttp
coughs up an error. The examples are way too simple and the docs are mute
on this problem. If you can't insert boundary lines nor the intermediate
field data it seems that it is impossible to generate a valid
multipart/form-data POST using winhttp.
Is this the case for the current version of the winhttp library?