Uploading a byte array to a HTTP server
I would like to upload a byte array to a HTTP(S) server. I am aware that this can be done using the WebClient but I would like to send some POST arguments along with the byte array.
How can I do this with more fundemental classes like HTTPWebRequest? These are the conditions that the solution should m开发者_JS百科eet:
- It should also work in HTTPS.
- It should not require the byte array to be written to a temporary file. What I mean is that I should be able to do everything right within the memory.
Also, if the solution requires something different to be done over the server side, it would be great if you also state that.
Thanks in advance.
You should check this question:
Multipart forms from C# client
especially this answer:
https://stackoverflow.com/a/769093/213550
There is a lot of code, but the main idea is:
- Set the Request's
ContentType
to themultipart/form-data
- Add the boundary and the byte array to the Request's body
- Get the Response.
精彩评论