Skip to content

Commit 36226f5

Browse files
committed
fix(api): 使用 busybox nc 替代 curl 发送 API 请求
1 parent cf1ba76 commit 36226f5

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

  • src/module/scripts/utils

src/module/scripts/utils/api.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,25 @@ api_request() {
5353
local method="$1"
5454
local path="$2"
5555
local data="${3:-}"
56-
local controller secret
57-
58-
command_exists curl || return 1
56+
local controller secret host port
5957

6058
controller="$(api_controller)"
6159
secret="$(api_secret)"
62-
63-
if [ -n "$data" ]; then
64-
curl -fsS --connect-timeout 3 --max-time 10 \
65-
-X "$method" \
66-
-H "Authorization: Bearer $secret" \
67-
-H "Content-Type: application/json" \
68-
-d "$data" \
69-
"http://$controller$path"
70-
else
71-
curl -fsS --connect-timeout 3 --max-time 10 \
72-
-X "$method" \
73-
-H "Authorization: Bearer $secret" \
74-
"http://$controller$path"
75-
fi
60+
host="${controller%%:*}"
61+
port="${controller##*:}"
62+
63+
{
64+
printf "%s %s HTTP/1.1\r\n" "$method" "$path"
65+
printf "Host: %s\r\n" "$controller"
66+
printf "Authorization: Bearer %s\r\n" "$secret"
67+
if [ -n "$data" ]; then
68+
printf "Content-Type: application/json\r\n"
69+
printf "Content-Length: %d\r\n" "${#data}"
70+
fi
71+
printf "Connection: close\r\n"
72+
printf "\r\n"
73+
[ -n "$data" ] && printf "%s" "$data"
74+
} | "$(detect_busybox)" nc "$host" "$port" 2>/dev/null | sed '1,/^\r$/d'
7675
}
7776

7877
#######################################

0 commit comments

Comments
 (0)