Curl -d vs --data-binary












0















Using this [https://github.com/prometheus/pushgateway][1] we are trying to push one metric to prometheus. It seems to require the data in a very specific format.



It works fine when doing their example curl of



echo "some_metric 3.14" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job


Yet doing a curl with -d option fails as missing end of line/file



curl -d 'some_metric 3.15n' 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?










share|improve this question























  • why are you combining questions here. Are you trying to understand the behaviour of curl command with its different flags? or are you trying to send a NodeJS POST request to push metrics to push Gateway?

    – Andres Leon Rangel
    yesterday
















0















Using this [https://github.com/prometheus/pushgateway][1] we are trying to push one metric to prometheus. It seems to require the data in a very specific format.



It works fine when doing their example curl of



echo "some_metric 3.14" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job


Yet doing a curl with -d option fails as missing end of line/file



curl -d 'some_metric 3.15n' 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?










share|improve this question























  • why are you combining questions here. Are you trying to understand the behaviour of curl command with its different flags? or are you trying to send a NodeJS POST request to push metrics to push Gateway?

    – Andres Leon Rangel
    yesterday














0












0








0








Using this [https://github.com/prometheus/pushgateway][1] we are trying to push one metric to prometheus. It seems to require the data in a very specific format.



It works fine when doing their example curl of



echo "some_metric 3.14" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job


Yet doing a curl with -d option fails as missing end of line/file



curl -d 'some_metric 3.15n' 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?










share|improve this question














Using this [https://github.com/prometheus/pushgateway][1] we are trying to push one metric to prometheus. It seems to require the data in a very specific format.



It works fine when doing their example curl of



echo "some_metric 3.14" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job


Yet doing a curl with -d option fails as missing end of line/file



curl -d 'some_metric 3.15n' 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?







node.js curl prometheus






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 11:53









sradforthsradforth

1,9231730




1,9231730













  • why are you combining questions here. Are you trying to understand the behaviour of curl command with its different flags? or are you trying to send a NodeJS POST request to push metrics to push Gateway?

    – Andres Leon Rangel
    yesterday



















  • why are you combining questions here. Are you trying to understand the behaviour of curl command with its different flags? or are you trying to send a NodeJS POST request to push metrics to push Gateway?

    – Andres Leon Rangel
    yesterday

















why are you combining questions here. Are you trying to understand the behaviour of curl command with its different flags? or are you trying to send a NodeJS POST request to push metrics to push Gateway?

– Andres Leon Rangel
yesterday





why are you combining questions here. Are you trying to understand the behaviour of curl command with its different flags? or are you trying to send a NodeJS POST request to push metrics to push Gateway?

– Andres Leon Rangel
yesterday












1 Answer
1






active

oldest

votes


















1














From curl man page:




--data-ascii



(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.15n".



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






share|improve this answer
























  • Many thanks for your detailed response. Any idea how I can get node.js to POST data that matches the --data-binary curl command? It seems it should just be a case of adding a n to the data it is POSTing? The weird thing seems that the n approach didn't seem to work hence why I'm curious what else it does differently.

    – sradforth
    Nov 15 '18 at 12:24











  • @sradforth, I'm not quite familiar with NodeJS but you can take a look here: stackoverflow.com/questions/38030484/… Also, it'd be helpful if you send a file you're trying to send and a piece of code that does the file upload

    – StasKolodyuk
    Nov 15 '18 at 12:41











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318936%2fcurl-d-vs-data-binary%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














From curl man page:




--data-ascii



(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.15n".



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






share|improve this answer
























  • Many thanks for your detailed response. Any idea how I can get node.js to POST data that matches the --data-binary curl command? It seems it should just be a case of adding a n to the data it is POSTing? The weird thing seems that the n approach didn't seem to work hence why I'm curious what else it does differently.

    – sradforth
    Nov 15 '18 at 12:24











  • @sradforth, I'm not quite familiar with NodeJS but you can take a look here: stackoverflow.com/questions/38030484/… Also, it'd be helpful if you send a file you're trying to send and a piece of code that does the file upload

    – StasKolodyuk
    Nov 15 '18 at 12:41
















1














From curl man page:




--data-ascii



(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.15n".



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






share|improve this answer
























  • Many thanks for your detailed response. Any idea how I can get node.js to POST data that matches the --data-binary curl command? It seems it should just be a case of adding a n to the data it is POSTing? The weird thing seems that the n approach didn't seem to work hence why I'm curious what else it does differently.

    – sradforth
    Nov 15 '18 at 12:24











  • @sradforth, I'm not quite familiar with NodeJS but you can take a look here: stackoverflow.com/questions/38030484/… Also, it'd be helpful if you send a file you're trying to send and a piece of code that does the file upload

    – StasKolodyuk
    Nov 15 '18 at 12:41














1












1








1







From curl man page:




--data-ascii



(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.15n".



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






share|improve this answer













From curl man page:




--data-ascii



(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.15n".



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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 12:11









StasKolodyukStasKolodyuk

1,5661526




1,5661526













  • Many thanks for your detailed response. Any idea how I can get node.js to POST data that matches the --data-binary curl command? It seems it should just be a case of adding a n to the data it is POSTing? The weird thing seems that the n approach didn't seem to work hence why I'm curious what else it does differently.

    – sradforth
    Nov 15 '18 at 12:24











  • @sradforth, I'm not quite familiar with NodeJS but you can take a look here: stackoverflow.com/questions/38030484/… Also, it'd be helpful if you send a file you're trying to send and a piece of code that does the file upload

    – StasKolodyuk
    Nov 15 '18 at 12:41



















  • Many thanks for your detailed response. Any idea how I can get node.js to POST data that matches the --data-binary curl command? It seems it should just be a case of adding a n to the data it is POSTing? The weird thing seems that the n approach didn't seem to work hence why I'm curious what else it does differently.

    – sradforth
    Nov 15 '18 at 12:24











  • @sradforth, I'm not quite familiar with NodeJS but you can take a look here: stackoverflow.com/questions/38030484/… Also, it'd be helpful if you send a file you're trying to send and a piece of code that does the file upload

    – StasKolodyuk
    Nov 15 '18 at 12:41

















Many thanks for your detailed response. Any idea how I can get node.js to POST data that matches the --data-binary curl command? It seems it should just be a case of adding a n to the data it is POSTing? The weird thing seems that the n approach didn't seem to work hence why I'm curious what else it does differently.

– sradforth
Nov 15 '18 at 12:24





Many thanks for your detailed response. Any idea how I can get node.js to POST data that matches the --data-binary curl command? It seems it should just be a case of adding a n to the data it is POSTing? The weird thing seems that the n approach didn't seem to work hence why I'm curious what else it does differently.

– sradforth
Nov 15 '18 at 12:24













@sradforth, I'm not quite familiar with NodeJS but you can take a look here: stackoverflow.com/questions/38030484/… Also, it'd be helpful if you send a file you're trying to send and a piece of code that does the file upload

– StasKolodyuk
Nov 15 '18 at 12:41





@sradforth, I'm not quite familiar with NodeJS but you can take a look here: stackoverflow.com/questions/38030484/… Also, it'd be helpful if you send a file you're trying to send and a piece of code that does the file upload

– StasKolodyuk
Nov 15 '18 at 12:41




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318936%2fcurl-d-vs-data-binary%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine