0
0
Bash Scriptingscripting~10 mins

HTTP requests with curl in scripts in Bash Scripting - Interactive Code Practice

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

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

Bash Scripting
curl [1] https://example.com
Drag options to blanks, or click blank then click option'
A-o
B-X GET
C-I
D-d
Attempts:
3 left
💡 Hint
Common Mistakes
Using -d which is for sending data, not for GET requests.
Using -I which fetches headers only.
Using -o which saves output to a file.
2fill in blank
medium

Complete the code to send a POST request with data 'name=John' using curl.

Bash Scripting
curl -X POST [1] 'name=John' https://example.com/api
Drag options to blanks, or click blank then click option'
A-d
B-I
C-H
D-o
Attempts:
3 left
💡 Hint
Common Mistakes
Using -H which is for headers, not data.
Using -I which fetches headers only.
Using -o which saves output to a file.
3fill in blank
hard

Fix the error in the code to include a header 'Content-Type: application/json' in the curl request.

Bash Scripting
curl -X POST [1] 'Content-Type: application/json' https://example.com/api
Drag options to blanks, or click blank then click option'
A-I
B-d
C-o
D-H
Attempts:
3 left
💡 Hint
Common Mistakes
Using -d which is for data, not headers.
Using -I which fetches headers only.
Using -o which saves output to a file.
4fill in blank
hard

Fill both blanks to save the output of a GET request to a file named 'response.txt' and show only the HTTP status code.

Bash Scripting
curl [1] https://example.com -o [2]
Drag options to blanks, or click blank then click option'
A-w '%{http_code}' -s
B-I
Cresponse.txt
D-X POST
Attempts:
3 left
💡 Hint
Common Mistakes
Using -I which fetches headers only, not saving output.
Using -X POST which changes the method incorrectly.
Not specifying the output file name.
5fill in blank
hard

Fill all three blanks to send a POST request with JSON data '{"user":"admin"}', include the correct header, and save the response to 'result.json'.

Bash Scripting
curl [1] [2] -d '{"user":"admin"}' https://example.com/api -o [3]
Drag options to blanks, or click blank then click option'
A-X POST
B-H 'Content-Type: application/json'
Cresult.json
D-d
Attempts:
3 left
💡 Hint
Common Mistakes
Not setting the content type header correctly.
Forgetting to specify the POST method.
Not saving the output to a file.