I created an HTTP listener that accepts POST requests for files. I followed this template almost exactly: https://github.com/cpp-netlib/cpp-netlib/blob/main/libs/network/example/http/echo_async_server.cpp
I start my listener like so: ./build/http_listener 0.0.0.0 8000
Then post file to the listener using curl: curl --form "fileupload=@file1.txt" -X POST http://127.0.0.1:8000/
I noticed that the variable body__
, which gets populated with the text of the file also gets populated with header data. I do not want this. How do I populate the variable body__
without any header data?
This is what it looks like:
body__
does not get populated with header data. What you see is multipart data that you submit with --form <name=content>
. If you want submit raw file data use another curl command:
curl --data-binary "@file1.txt" -H "Content-Type: application/octet-stream" http://127.0.0.1:8000/
-X POST
can be omitted if is used with --data-binary
, --data
, --form
.
Unfortunately curl does not send a file name. If a file name is required on a server side, specify the header Content-Disposition
:
curl --data-binary "@file1.txt" -H "Content-Type: application/octet-stream" -H "Content-Disposition: attachment; filename=file1.txt" http://127.0.0.1:8000/
KB