views:

692

answers:

2

This should be very trivial but for reason can't find it. I'm posting some binary data to a form in ASP.NET as multipart/form-data and I can see that the request is receive by looking at Request.InputStream :

-------------------------------7cf2a327f01ae Content-Disposition: form-data; name="DeviceID1"

Some binary data

-------------------------------7cf2a327f01ae Content-Disposition: form-data; name="DeviceID2"

Some binary data ...

However I can't find how I can retrieve each part as part of the Request.Form (or Request.Params) collection. What could be wrong? One work around is to use a filename then retrieve from Request.Files but I wonder what is the proper way of getting the content. Thanks.

+1  A: 

Request.Files is the only way to retrieve the binary data that's posted to the server.

Agent_9191
I found that my work around doesn't work either. Even with the filename in the post data, I still get Request.Files.Count as 0. So something else must be wrong although I can see the request comes in properly.
msha
Are you using html file inputs or asp.net file controls?
Jim Schubert
No, the request is generated manually using HttpWebRequest
msha
A: 

I found that one problem was the line break and that the request should be terminated with a proper separator like this:

-------------------------------7cf2a327f01ae
Content-Disposition: form-data; name="DeviceID1"

Some binary data

-------------------------------7cf2a327f01ae 
Content-Disposition: form-data; name="DeviceID2"

Some binary data
-------------------------------7cf2a327f01ae

Now the keys appear in Request.Form however this collection is of type string so I decided to use the filename and then get from Request.Files. Or I could parse the entire request content completely manually.

msha