49

I have this curl command:

curl -k -d . -o SessionRequest.txt 
"https://myserver.com/MyWebApi/user?companysn=1234&login=my_login&password=my_password&ApiKey=my_api_key"

What does -d . stand for? What does it do?

Yves M.
  • 29,855
  • 23
  • 108
  • 144
user1523271
  • 1,005
  • 2
  • 13
  • 27

1 Answers1

65

Whenever your have a doubt use man.

Issue man curl and read about -d switch.

-d, --data <data>
    (HTTP)  Sends  the  specified data in a POST request to the HTTP
    cause curl to pass the data to the server using the content-type
    -d, --data is the same as --data-ascii. --data-raw is almost the
    ter.  To  post  data  purely  binary, you should instead use the
    [...]
    

It allows you to send ASCII data, eg.:

curl -d '{"hello": "world"}' -X POST -H "Content-Type: application/json" https://example.com

Send a JSON string to the server.

In your example, it just send a . character as ASCII data to the server. What it does depends on the server logic and is out of the curl command scope.

This said, we can guess what a . (dot, period, full stop) might mean in computer science:

  • Dot is a placeholder for the current directory in Unix File Systems;
  • Dot is a wildcard for any character in most Regular Expression grammars;
  • Dot is the separator between labels in domain name;
  • Dot is a common separator for filename and extension;

Nota: It is considered as a bad practice to send credentials using GET parameters, avoid it if you can and read more.

jlandercy
  • 7,183
  • 1
  • 39
  • 57
  • 6
    I did read the man page but could not understand anything. I still cant understand what the "." does. – user1523271 Oct 10 '17 at 18:47
  • The "." does nothing magic. It is a text "." that will be sent as data. – Eric Obermühlner Oct 25 '20 at 15:24
  • @EricObermühlner, indeed this is out of scope of curl command. This is delegated to the server logic behind. Curl is just the middleman. – jlandercy Oct 25 '20 at 16:09
  • Using a bash session to a Debian 9 (stretch) instance, I use `curl --help` to get the help documentation – Chris Halcrow Jul 09 '21 at 00:10
  • 3
    Note that `-d` w/o any header passes `content-type: application/x-www-form-urlencoded` header implicitly so you might get surprising result based on how you're passing value to `-d` – shriek Aug 20 '22 at 01:46
  • @shriek that's freaking important, thanks for pointing it out – refex Mar 14 '23 at 22:22