2

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 meet:

  • 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.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
Can Selcik
  • 23
  • 2
  • 4

1 Answers1

2

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:

  1. Set the Request's ContentType to the multipart/form-data
  2. Add the boundary and the byte array to the Request's body
  3. Get the Response.
Community
  • 1
  • 1
VMAtm
  • 27,943
  • 17
  • 79
  • 125