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

|
||||

|
||||
|
||||

|
||||
|
||||
|
|
|
|||
18
curl.sh
18
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,14 +17,17 @@ 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
|
||||
# Parse each newline as a separate parameter joined by a "&"
|
||||
params=$(tr '\n' '&' < "$REQ_PARAMS_FILE" | sed 's/&$//')
|
||||
|
||||
if [ -n "$params" ]; then
|
||||
url="${url}?${params}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Prepare curl
|
||||
curl_cmd="curl -s"
|
||||
|
|
@ -63,11 +66,12 @@ fi
|
|||
# Save the response headers and body
|
||||
curl_cmd="$curl_cmd -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE"
|
||||
|
||||
# Execute curl
|
||||
eval "clear"
|
||||
|
||||
echo -e "${method} ${url}"
|
||||
# Dispatch request
|
||||
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