curl -d 'some_metric 3.15\n' http://pushgateway.example.org:9091/metrics/job/some_job
I'm trying to understand the difference in behaviour since I believe both are doing POST commands and I need to replicate this --data-binary option in node.js via "request.post" method but I seem to only be able to replicate the curl -d option which doesn't work.
Any suggestions on hints on what the difference is between -d and --data-binary and to do the equivalent to --data-binary from within node.js?
–
–
(HTTP) This is just an alias for -d, --data.
--data-binary
(HTTP) This posts data exactly as specified with no extra processing whatsoever.
If you start the data with the letter @, the rest should be a filename. Data is posted > in a similar manner as -d, --data does, except that newlines and carriage returns are > > preserved and conversions are never done.
Like -d, --data the default content-type sent to the server is application/x-www-form-> > urlencoded. If you want the data to be treated as arbitrary binary data by the server > then set the content-type to octet-stream: -H "Content-Type: application/octet-stream".
If this option is used several times, the ones following the first will append data as > described in -d, --data.
Using @-
will make curl read the filename from stdin.
So, basically in your first variant you send a binary file named "some_metric 3.14".
In the second one, you're sending an ascii string "some_metric 3.15\n".
If you want curl to strip new lines before sending, use --data-ascii or -d option:
echo "some_metric 3.14" | curl -d @- http://pushgateway.example.org:9091/metrics/job/some_job
–
–
–
–
-d
(or --data
) and --data-binary
are exactly the same if you're just passing a normal value like this:
curl --data somekey=somevalue example.com
But if you're telling curl to read the value from a file by passing --data @filename
(or @-
to read from stdin) like this:
curl --data @./some/path/to/a/file.txt example.com
then the difference is that --data
removes all \n
and \r
characters in the file, whereas --data-binary
just sends the file as-is.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.