mirror of
https://codeberg.org/vlw/curl.git
synced 2025-09-14 00:33:41 +02:00
56 lines
No EOL
1.3 KiB
Bash
Executable file
56 lines
No EOL
1.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Check if the correct number of arguments is provided
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Usage: $0 <url> <request_method>"
|
|
exit 1
|
|
fi
|
|
|
|
URL="$1"
|
|
METHOD="$2"
|
|
KEY_FILE="key.txt"
|
|
PARAMS_FILE="params.txt"
|
|
PAYLOAD_FILE="payload.json"
|
|
DISABLE_SSL_FILE="disable_peer_validation"
|
|
|
|
# Append URL search parameters from params.txt
|
|
if [ -f $PARAMS_FILE ]; then
|
|
PARAMS=$(<params.txt)
|
|
URL="${URL}?${PARAMS}"
|
|
fi
|
|
|
|
# Check if the key file exists and read the Bearer token
|
|
if [ -f $KEY_FILE ]; then
|
|
BEARER_TOKEN=$(<"$KEY_FILE")
|
|
else
|
|
echo "Error: Bearer token file '$KEY_FILE' not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Prepare the curl command
|
|
CURL_CMD="curl -s -H \"Authorization: Bearer ${BEARER_TOKEN}\""
|
|
|
|
# Check if SSL peer validation should be disabled
|
|
if [ -f $DISABLE_SSL_FILE ]; then
|
|
CURL_CMD="$CURL_CMD -k"
|
|
fi
|
|
|
|
# Add the request method and URL to the curl command
|
|
CURL_CMD="$CURL_CMD -X $METHOD \"$URL\""
|
|
|
|
# If the method is not GET, include the payload
|
|
if [ $METHOD != "GET" ]; then
|
|
if [ -f "$PAYLOAD_FILE" ]; then
|
|
PAYLOAD=$(<"$PAYLOAD_FILE")
|
|
CURL_CMD="$CURL_CMD -H \"Content-Type: application/json\" -d '$PAYLOAD'"
|
|
else
|
|
echo "Error: Payload file '${PAYLOAD_FILE}' not found."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Execute the curl command
|
|
eval "clear"
|
|
echo -e "${METHOD} ${URL}\n"
|
|
eval $CURL_CMD
|
|
echo -e "" |