Skip to content
Advertisement

curl: What’s the difference between -d and –data-binary options?

I’m trying to send a post request to a REST API. I noticed that everything works fine when I pass parameters with -d option in curl. Example:

curl "https://mywebsite.com" -d "param1=x" -d "param2=y" -u "3SUHZb0sanKWrQ"

However, if a send parameters as a json object and using –data-binary, I receive an error from the Api (as if no parameters were received). Example:

curl "https://mywebsite.com" --data-binary $'{ "param1": "x", -d "param2":"y" }' -u "3SUHZb0sanKWrQ"

I thought the two approaches had the same behavior, but I think I’m wrong. What’s the difference between these two approaches?

P.S.: the second request is the curl request that I get when select copy as cURL option on Google Chrome, because the actual request is a $http.post in Angular with its data payload as a JSON object. What can I do in Angular to get it working?

var data = { 
  "param1": "x", 
  "param2": "y" 
};

$http({
    url: "https://mywebsite.com",
    method: 'POST',
    data: data
}).then(function successCallback(response){
    console.log(response);
}, function errorCallback(response){
    console.log(response);
});

Advertisement

Answer

This is what I got with curl --help:

 -d, --data DATA     HTTP POST data (H)
     --data-raw DATA  HTTP POST data, '@' allowed (H)
     --data-ascii DATA  HTTP POST ASCII data (H)
     --data-binary DATA  HTTP POST binary data (H)
     --data-urlencode DATA  HTTP POST data url encoded (H)
     --delegation STRING  GSS-API delegation permission
     --digest        Use HTTP Digest Authentication (H)
     --disable-eprt  Inhibit using EPRT or LPRT (F)
     --disable-epsv  Inhibit using EPSV (F)
     --dns-servers   DNS server addrs to use: 1.1.1.1;2.2.2.2
     --dns-interface  Interface to use for DNS requests
     --dns-ipv4-addr  IPv4 address to use for DNS requests, dot notation
     --dns-ipv6-addr  IPv6 address to use for DNS requests, dot notationĀ§

So, the difference is just that with -d data sent is not binary content.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement