DEV Community

K-Sato
K-Sato

Posted on

Basic curl options

Overview

Here are some super basic curl command options all web-application-developers should know.
If there is/are any other command option/options, you think, should be on the list, plz leave a comment below with the option/options.

Add headers

You can use -H to add headers to your request.

$ curl -H "Content-Type: application/json" http://localhost:8888
Enter fullscreen mode Exit fullscreen mode

Make a POST request with Parameters

You can make a post request with parameters with the -d (-data) flag.
You can specify the method you want to use with -X. In this case, you are specifying to use the POST method.

$ curl -d '{"name":"value1", "content":"value2"}'  -X POST http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

Get verbose response

You can get verbose response with the -v option. The -v stands for -verbose.

$ curl -v http://localhost:8888
Enter fullscreen mode Exit fullscreen mode

Fetch only the HTTP headers

You can use -I/--head flag to only fetch the headers.

$ curl -I http://localhost:8888
Enter fullscreen mode Exit fullscreen mode

Add cookies

You can pass the data to the HTTP server as a cookie with the -b/--cookie command.
NOTE that the file specified with -b/--cookie is only used as input. No cookies will be stored in the file. To store cookies, use the -c/--cookie-jar option

$ curl -c cookie.txt -b cookie.txt -b "name=value" http://example.com
Enter fullscreen mode Exit fullscreen mode

Send Data like sending them via forms

This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the content-type multipart/form-data according to RFC1867.

$ curl -F title="Test" -F author="Test" -F attachment-file=@test.txt http://localhost:8880
Enter fullscreen mode Exit fullscreen mode

Resources

Here are some resources to know more about the curl command.

Top comments (24)

Collapse
 
pranay_rauthu profile image
pranay rauthu

writing curl commands is pain. I have created a tool to generate them.

pranayrauthu.github.io/fetcher/#/curl

Collapse
 
seoexpert21 profile image
Seo Expert

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. band 7 nhs take home pay

Collapse
 
masyamtot profile image
Mas YamTOT • Edited

sewa Mobil Jogja Lepas Kunci 24 jam Mulai 150 Ribu Di Sekitar Malioboro

Liburan di Yogyakarta, kota budaya yang kaya akan sejarah dan keindahan alam, adalah impian bagi banyak orang. Namun, untuk menjelajahi semua yang ditawarkan kota ini dengan kenyamanan dan kebebasan penuh, rental mobil kunci adalah pilihan yang bijaksana. Dalam artikel ini, kita akan membahas mengapa sewa mobil lepas kunci di Jogja adalah pilihan terbaik untuk liburan Anda.

Collapse
 
rankingsoe21 profile image
rankingseo21

Thanks for taking the time to discuss this, I feel strongly that love and read more on this topic. If possible, such as gain knowledge, would you mind updating your blog with additional information? It is very useful for me. Minecraft PE Apk

Collapse
 
meave9786 profile image
meave9786

Hope you guys can be see this amazing blog online here how to get free robux without human verification save to batter way of enjoy.

Collapse
 
sprunkiretake profile image
SprunkiRetake

This is very useful post for me. This will absolutely going to help me in my project.

Collapse
 
doramamp4 profile image
doramasflix

Writing curl commands can be a hassle, so I developed a tool to generate them easily. doramasflix

Collapse
 
wplacetool profile image
yesanson

Great post on basic curl options! I found the tips on adding headers and making POST requests really helpful for my web development work. Thanks for sharing these essentials.

Collapse
 
neal1980 profile image
Neal

writing curl commands is pain. I have created a tool to generate them at neal fun.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.