Bird
Raised Fist0
Linux CLIscripting~10 mins

curl for HTTP requests in Linux CLI - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send a simple GET request to example.com using curl.

Linux CLI
curl [1]
Drag options to blanks, or click blank then click option'
A-d 'data' http://example.com
B-X POST http://example.com
Chttp://example.com
D-I http://example.com
Attempts:
3 left
💡 Hint
Common Mistakes
Using -X POST when you want a GET request.
Adding data (-d) when not needed.
Using -I which only fetches headers.
2fill in blank
medium

Complete the code to send a POST request with curl to http://example.com.

Linux CLI
curl [1] http://example.com
Drag options to blanks, or click blank then click option'
A-X GET
B-X POST
C-L
D-I
Attempts:
3 left
💡 Hint
Common Mistakes
Using -X GET instead of POST.
Using -I which only fetches headers.
Using -L which follows redirects but does not change method.
3fill in blank
hard

Fix the error in the curl command to send JSON data with POST to http://example.com.

Linux CLI
curl -X POST -H 'Content-Type: application/json' -d [1] http://example.com
Drag options to blanks, or click blank then click option'
A"name=John"
B{"name":"John"}
C'name=John'
D'{"name":"John"}'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting JSON properly causing shell errors.
Using URL-encoded format instead of JSON.
Missing quotes causing syntax errors.
4fill in blank
hard

Fill both blanks to save the output of a curl GET request to a file named response.txt.

Linux CLI
curl [1] [2]
Drag options to blanks, or click blank then click option'
A-o response.txt
Bhttp://example.com
C-O
D-I
Attempts:
3 left
💡 Hint
Common Mistakes
Using -I which only fetches headers.
Using -O which saves with original filename, not custom.
Putting options in wrong order.
5fill in blank
hard

Fill all three blanks to send a POST request with JSON data and include a custom header.

Linux CLI
curl [1] -H [2] -d [3] http://example.com
Drag options to blanks, or click blank then click option'
A-X POST
B'Authorization: Bearer token123'
C'{"id":5}'
D-I
Attempts:
3 left
💡 Hint
Common Mistakes
Using -I which only fetches headers.
Not quoting header or data properly.
Missing -X POST option.

Practice

(1/5)
1. What does the curl command primarily do in Linux?
easy
A. Monitor system processes
B. Send HTTP requests to websites
C. Manage file permissions
D. Compile source code

Solution

  1. Step 1: Understand the purpose of curl

    The curl command is designed to send HTTP requests and interact with web servers.
  2. Step 2: Compare with other options

    Compiling code, managing permissions, and monitoring processes are unrelated to curl's function.
  3. Final Answer:

    Send HTTP requests to websites -> Option B
  4. Quick Check:

    curl = HTTP requests [OK]
Hint: curl is for web requests, not system tasks [OK]
Common Mistakes:
  • Confusing curl with system commands like chmod or ps
  • Thinking curl compiles code
  • Assuming curl manages files locally
2. Which of the following is the correct syntax to fetch the content of http://example.com using curl?
easy
A. curl http://example.com
B. curl --head http://example.com
C. curl -x http://example.com
D. curl -d http://example.com

Solution

  1. Step 1: Identify basic curl usage

    To fetch a webpage, simply use curl URL. No extra flags are needed for a simple GET request.
  2. Step 2: Analyze other options

    -x is for proxy, --head fetches headers only, -d sends data (POST), so they are incorrect for simple fetch.
  3. Final Answer:

    curl http://example.com -> Option A
  4. Quick Check:

    Basic fetch = curl URL [OK]
Hint: Use curl followed by URL to fetch page [OK]
Common Mistakes:
  • Using -x which is for proxy
  • Using -d which sends data instead of fetching
  • Using --head which fetches headers only
3. What will be the output of this command?
curl -I https://example.com
medium
A. An error because -I is invalid
B. The full HTML content of the page
C. Only the HTTP headers of the response
D. The page content saved to a file

Solution

  1. Step 1: Understand the -I option in curl

    The -I flag tells curl to fetch only the HTTP headers, not the full content.
  2. Step 2: Check other options

    The full HTML content of the page is full content, which -I does not do. An error because -I is invalid is wrong because -I is valid. The page content saved to a file requires -o flag, not present here.
  3. Final Answer:

    Only the HTTP headers of the response -> Option C
  4. Quick Check:

    -I = headers only [OK]
Hint: Remember -I fetches headers only [OK]
Common Mistakes:
  • Thinking -I fetches full page
  • Confusing -I with -o for output file
  • Assuming -I is invalid flag
4. You want to send JSON data {"name":"John"} to http://api.example.com/users using curl. Which command has an error?
medium
A. curl -d '{name:John}' -X POST -H "Content-Type: application/json" http://api.example.com/users
B. curl -X POST -H "Content-Type: application/json" -d '{"name":"John"}' http://api.example.com/users
C. curl -d '{"name":"John"}' http://api.example.com/users -H "Content-Type: application/json" -X POST
D. curl -X POST -d '{"name":"John"}' -H "Content-Type: application/json" http://api.example.com/users

Solution

  1. Step 1: Check JSON data format

    curl -d '{name:John}' -X POST -H "Content-Type: application/json" http://api.example.com/users uses '{name:John}' which misses double quotes around keys and values, making it invalid JSON. Options A, C, D use correct JSON '{"name":"John"}'.
  2. Step 2: Confirm curl flags order

    Order of flags does not matter in curl, so A, C, D are valid. Only data format in B is wrong.
  3. Final Answer:

    curl -d '{name:John}' -X POST -H "Content-Type: application/json" http://api.example.com/users -> Option A
  4. Quick Check:

    JSON must have quotes [OK]
Hint: JSON keys and values need quotes [OK]
Common Mistakes:
  • Omitting quotes in JSON data
  • Thinking flag order matters in curl
  • Using wrong content-type header
5. You want to download a file from http://example.com/file.zip and save it as myfile.zip. Which curl command does this correctly?
hard
A. curl --save myfile.zip http://example.com/file.zip
B. curl -O http://example.com/file.zip > myfile.zip
C. curl -O myfile.zip http://example.com/file.zip
D. curl -o myfile.zip http://example.com/file.zip

Solution

  1. Step 1: Understand curl file saving options

    -o filename saves the download to the specified filename. -O saves with original name from URL.
  2. Step 2: Analyze each option

    B: curl -O http://example.com/file.zip > myfile.zip saves to 'file.zip' via -O and redirects empty stdout to myfile.zip. C: curl -O myfile.zip http://example.com/file.zip uses -O incorrectly, treating myfile.zip as URL. D: uses invalid flag --save.
  3. Final Answer:

    curl -o myfile.zip http://example.com/file.zip -> Option D
  4. Quick Check:

    -o sets output filename [OK]
Hint: Use -o to name downloaded file [OK]
Common Mistakes:
  • Using > redirection for binary files
  • Confusing -O and -o flags
  • Using non-existent flags like --save
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard