mirror of
https://codeberg.org/vlw/curl.git
synced 2026-04-13 10:49:39 +02:00
Compare commits
No commits in common. "master" and "2.1.1" have entirely different histories.
2 changed files with 9 additions and 13 deletions
|
|
@ -1,4 +1,4 @@
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
|
||||||
18
curl.sh
18
curl.sh
|
|
@ -1,8 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Check if the correct number of arguments is provided
|
# Check if the correct number of arguments is provided
|
||||||
if [ -z "${1:-}" ]; then
|
if [ "$#" -ne 2 ]; then
|
||||||
echo "Usage: $0 <url> [request_method]"
|
echo "Usage: $0 <url> <request_method>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -17,16 +17,13 @@ RESP_BODY_RAW_FILE="curl/resp_body.txt"
|
||||||
RESP_BODY_JSON_FILE="curl/resp_body.json"
|
RESP_BODY_JSON_FILE="curl/resp_body.json"
|
||||||
|
|
||||||
url="$1"
|
url="$1"
|
||||||
method="${2:-GET}"
|
method="$2"
|
||||||
|
|
||||||
# Append url search parameters
|
# Append url search parameters
|
||||||
if [ -f $REQ_PARAMS_FILE ]; then
|
if [ -f $REQ_PARAMS_FILE ]; then
|
||||||
# Parse each newline as a separate parameter joined by a "&"
|
# Parse each newline as a separate parameter joined by a "&"
|
||||||
params=$(tr '\n' '&' < "$REQ_PARAMS_FILE" | sed 's/&$//')
|
params=$(tr '\n' '&' < "$REQ_PARAMS_FILE" | sed 's/&$//')
|
||||||
|
|
||||||
if [ -n "$params" ]; then
|
|
||||||
url="${url}?${params}"
|
url="${url}?${params}"
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prepare curl
|
# Prepare curl
|
||||||
|
|
@ -66,12 +63,11 @@ fi
|
||||||
# Save the response headers and body
|
# Save the response headers and body
|
||||||
curl_cmd="$curl_cmd -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE"
|
curl_cmd="$curl_cmd -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE"
|
||||||
|
|
||||||
# Dispatch request
|
# Execute curl
|
||||||
echo -e "\e[0;92mRequest >\e[0m ${method} ${url}"
|
eval "clear"
|
||||||
|
|
||||||
|
echo -e "${method} ${url}"
|
||||||
eval $curl_cmd
|
eval $curl_cmd
|
||||||
|
|
||||||
# Copy the raw respone body to a pretty-printed JSON file
|
# Copy the raw respone body to a pretty-printed JSON file
|
||||||
jq . $RESP_BODY_RAW_FILE > $RESP_BODY_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