0
0
Linux CLIscripting~20 mins

curl for HTTP requests in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Curl Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this curl command?
You run this command in a terminal:
curl -s -o /dev/null -w "%{http_code}" https://httpbin.org/status/404

What will be the output?
Linux CLI
curl -s -o /dev/null -w "%{http_code}" https://httpbin.org/status/404
ANo output
B404
CError: Not Found
D200
Attempts:
2 left
💡 Hint
The -w option prints the HTTP status code. The URL returns a 404 status.
💻 Command Output
intermediate
1:30remaining
What does this curl command output?
Consider this command:
curl -I https://example.com

What kind of output will it produce?
Linux CLI
curl -I https://example.com
AOnly the HTTP status code
BFull HTML content of the page
COnly HTTP headers of the response
DAn error message
Attempts:
2 left
💡 Hint
The -I option fetches headers only.
📝 Syntax
advanced
2:00remaining
Which curl command correctly sends JSON data with POST?
You want to send JSON data '{"name":"Alice"}' to https://api.example.com/users using POST. Which command is correct?
Acurl -X POST -H "Content-Type: application/json" https://api.example.com/users
Bcurl -X POST -d '{"name":"Alice"}' -H "Content-Type: text/plain" https://api.example.com/users
Ccurl -X GET -H "Content-Type: application/json" -d '{"name":"Alice"}' https://api.example.com/users
Dcurl -X POST -H "Content-Type: application/json" -d '{"name":"Alice"}' https://api.example.com/users
Attempts:
2 left
💡 Hint
Use POST method, set content type to application/json, and provide data with -d.
🔧 Debug
advanced
2:00remaining
Why does this curl command fail to send data?
This command is run:
curl -X POST https://api.example.com/data -d name=Bob&age=25

But the server reports only partial data received. Why?
Linux CLI
curl -X POST https://api.example.com/data -d name=Bob&age=25
AThe -d option needs quotes around the data to be sent correctly
BPOST method is not supported by curl
CThe -X POST option must come after the URL
DThe URL is missing a trailing slash
Attempts:
2 left
💡 Hint
Shell may split unquoted data into multiple arguments.
🚀 Application
expert
2:30remaining
How to save only HTTP response headers to a file using curl?
You want to save only the HTTP headers from https://example.com to a file named headers.txt, without saving the body. Which command does this?
Acurl -s -D headers.txt -o /dev/null https://example.com
Bcurl -s -I https://example.com > headers.txt
Ccurl -s -o headers.txt -I https://example.com
Dcurl -s -o headers.txt https://example.com
Attempts:
2 left
💡 Hint
Use -D to save headers, -o /dev/null to discard body.