What does the -d in this cURL command mean?

17,460

-d specifies the body of the request. From the man-page:

-d, --data (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.

-d, --data is the same as --data-ascii. --data-raw is almost the same but does not have a special interpretation of the @ character. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data-urlencode.

It is interesting that you use a service that uses GET with request bodies, as explained here, it is possible but unwanted.

For example; proxies are allowed to remove the body. But as long as there are no machines between you and their server, it might work; and they probably have software that allows them to interpret the body.

Share:
17,460
user3708584
Author by

user3708584

Updated on July 18, 2022

Comments

  • user3708584
    user3708584 almost 2 years

    I'm working on a program that's making calls to a RESTful api. All of the documentation for the api is cURL commands, but I can't make cURL commands, so I need to translate them and make the request a different way. This is the example code they provide for the kind of query I want to make.

    curl -u '{userEmail}:{userApiToken}' -v -X GET -H 'Content-Type: application/xml' -o 'result.xml' -d '<request><layout>1</layout><searchmode>Cany</searchmode><searchvalue>aaron</searchvalue><filtermode></filtermode><filtervalue></filtervalue><special></special><limit>100</limit><start></start><sortfield></sortfield><sortdir></sortdir></request>' https://secure.website.com/contacts  `
    

    I've been over the cURL documentation and understand all of the flags except for the -d. I get that its argument is xml of search parameters, but what does the -d mean on a GET cURL?

    Thanks

  • user3708584
    user3708584 over 8 years
    That's what I thought. But I didn't think GET requests had bodies. Am I wrong about that?
  • Sjon
    Sjon over 8 years
    I've expanded my answer