How can I rewrite the following CURL command, so that it doesn’t use the -F option, but still generates the exact same HTTP request? i.e. so that it passes the multipart/form-data in the body directly.
curl -X POST -F example=test http://localhost:3000/test
Solved:
Where
test.txtcontains the following text, and most importantly has CRLF (\r\n) line endings:Notes: it is important to use
--data-binaryinstead of plain old-das the former preserves the line endings (which are very important). Also, note that the boundary in the body starts with an extra--.I’m going to repeat it because it’s so important, but that request-body file must have CRLF line endings. A multi-platform text editor with good line-ending support is jEdit (how to set the line endings in jEdit).
If you’re interested in how I worked this out (debugging with a Ruby on Rails app) and not just the final solution, I wrote up my debugging steps on my blog.