26

I have a simple question regarding to the usage of cURL. Didn't find much during my Google search or Man page to get a clear answer.

In here talks about using either --data vs --form on sending file/attachment. I'm curious to know what are the main difference and under what scenarios you would pick --data-binary VS --form ?

The POST "body" can be sent via either --data (for application/x-www-form-urlencoded) or --form (for multipart/form-data):

-F "foo=bar"                  # 'foo' value is 'bar'
-F "foo=<foovalue.txt"        # the specified file is sent as plain text input
-F "[email protected]"        # the specified file is sent as an attachment

-d "foo=bar"
-d "foo=<foovalue.txt"
-d "[email protected]"
-d "@entirebody.txt"          # the specified file is used as the POST body

--data-binary "@binarybody.jpg"

2 Answers 2

13

The difference is explained in the HTML 4.01 Specification section on Forms:

application/x-www-form-urlencoded is the default content type.

The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.

Sign up to request clarification or add additional context in comments.

1 Comment

Would it fail if the content-type is specified as "multipart/form-data", but they send it as --data-binary, when using curl?
4

That's exactly the main difference, type of data that's being sent to the server (application/x-www-form-urlencoded vs multipart/form-data)

1 Comment

Thanks! What are the scenarios you will use either type of data? so form-urlencoded is for embedded the data into the request, but multipart is different?

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.