1

Alert I've seen some people have asked but its usually about CURL, I am asking about sending it via WinSock2.

Alright so I know how to make POST and GET statements pretty easily, (POST with Application/application/x-www-form-urlencoded) but I am not sure how to use multipart/form-data, I know it has something to do with boundary to specify when you are done sending data.

But what should a basic HTTP POST look like for uploading files? (Also can you upload to a PHP POSTBACK? If It was application/x-www-form-urlencoded I could see it something like filename=hello.png&data=...)

Something like this format: (This is all I know about sending the data) I can't find a solid example online so I am asking the question.

POST /postback.php HTTP/1.1
HOST: www.website.com
Content-Type: multipart/form-data; boundary=----IAmABoundary
Content-Length: 300

------IAmABoundary
Send Binary Data?
------IAmABoundary--
Trevin Corkery
  • 651
  • 7
  • 19

3 Answers3

0

Use fiddler to capture uploading a file then you can see the actual format, your example above is more or less right as I recall. Here is a much more complete answer with a good example: Example of multipart/form-data

Community
  • 1
  • 1
Chris Pugmire
  • 91
  • 1
  • 4
0

HTTP messages are MIME messages. It's actually a fairly complex encoding format.

Start by reading RFC 2045. This is the base specification for MIME.

Then, move on to RFC 2046. Section 5 of RFC 2046 lays out the specification for multipart MIME messages, which is used for the multipart/form-data format you're seeing.

It's a lot of material to read through, true. But it is imperative to fully understand MIME-formatted messages in order to have any hope of understand how file uploads work.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
0

if you want to send file content actually you can just put the file content into after the HTTP Headers, and set the content-type and the content-length

multipart/form-data is used by html form to post/submit form that have file in its field, they separated the parts/fields using the multipart boundary

izmanq
  • 11
  • 2