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.

6
  • msdn.microsoft.com/en-us/library/debx8sh9.aspx Commented Feb 13, 2011 at 15:43
  • @Jaroslav Jandek - What if I have other another data to send. Like sending the byte array and sending some other data. Commented Feb 13, 2011 at 16:27
  • 2
    Do you mean you want to simulate a multipart upload? Or could you sen te byte[] simply as a base-64 post argument? Commented Feb 13, 2011 at 16:27
  • Exactly, a multipart upload. I want to send the byte array and some other information at the same time. Commented Feb 13, 2011 at 16:28
  • 4
    stackoverflow.com/questions/219827/… Commented Feb 13, 2011 at 16:57

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.