Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the -d in this cURL command mean?

Tags:

rest

curl

xml

get

api

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

like image 553
user3708584 Avatar asked Sep 21 '15 17:09

user3708584


People also ask

What is the meaning of in curl command?

What Is the curl Command? curl (short for "Client URL") is a command line tool that enables data transfer over various network protocols. It communicates with a web or application server by specifying a relevant URL and the data that need to be sent or received.

What does flag mean in curl?

A flag is a command-line parameter that denotes a specific action in Curl. Curl has over three hundred command-line options, and the number of options increases over time. You can add the listed flags to the Curl command and enter the URL. Flags can be short (like o, -L, etc.) or extended (like --verbose).

What is H in curl?

The -H in curl indicates the headers of the request, so your curl will translate to php like: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://thewebsite.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPGET, 1); curl_setopt($ch, CURLOPT_USERPWD, "app:app"); $headers = [ "Content- ...

What is U in curl request?

To send a Curl request with a Basic Server Authentication, you need to send an HTTP request to the server and provide user credentials using the -u or --- user command-line parameter. Curl has a built-in mechanism for sending basic authorization to the server.


Video Answer


1 Answers

-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.

like image 65
Sjon Avatar answered Sep 26 '22 02:09

Sjon