mirror of
https://codeberg.org/vlw/curl.git
synced 2026-04-13 02:39:38 +02:00
Compare commits
4 commits
a42be0792c
...
832bea4252
| Author | SHA1 | Date | |
|---|---|---|---|
| 832bea4252 | |||
| 7b70a6e51d | |||
| e015174467 | |||
| 328cebc703 |
2 changed files with 8 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||

|
||||

|
||||
|
||||

|
||||
|
||||
|
|
|
|||
11
curl.sh
11
curl.sh
|
|
@ -1,8 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Check if the correct number of arguments is provided
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Usage: $0 <url> <request_method>"
|
||||
if [ -z "${1:-}" ]; then
|
||||
echo "Usage: $0 <url> [request_method]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ RESP_BODY_RAW_FILE="curl/resp_body.txt"
|
|||
RESP_BODY_JSON_FILE="curl/resp_body.json"
|
||||
|
||||
url="$1"
|
||||
method="$2"
|
||||
method="${2:-GET}"
|
||||
|
||||
# Append url search parameters
|
||||
if [ -f $REQ_PARAMS_FILE ]; then
|
||||
|
|
@ -66,8 +66,11 @@ curl_cmd="$curl_cmd -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE"
|
|||
# Execute curl
|
||||
eval "clear"
|
||||
|
||||
echo -e "${method} ${url}"
|
||||
echo -e "\e[0;92mRequest >\e[0m ${method} ${url}"
|
||||
eval $curl_cmd
|
||||
|
||||
# Copy the raw respone body to a pretty-printed JSON file
|
||||
jq . $RESP_BODY_RAW_FILE > $RESP_BODY_JSON_FILE
|
||||
|
||||
# Print the response code
|
||||
echo -e -n "\e[0;94mResponse <\e[0m "; head -n 1 $RESP_HEADERS_FILE
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue