0

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 "[email protected]" -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:

enter image description here

1 Answer 1

1

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

  1. --data-binary
  2. -F, --form
Sign up to request clarification or add additional context in comments.

3 Comments

wow, you are a life-saver thank you so much! This worked for me. Do you know how the HTTP listener can retrieve the name of the original file if a header is not passed? I want the HTTP listener to store the name of the original file inside a variable. I want to use this variable for various purposes.
See the update.
thank you!! I appreciate your help. My program works perfectly now

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.