Improve: Handle errors
Improve: Use curl for urlencode
Optimization: Auto convert HTTP method to uppercase
This commit is contained in:
Zhong Lufan
2020-04-28 23:09:28 +08:00
parent 68de6308ca
commit 36ed1f46d7
2 changed files with 11 additions and 15 deletions

View File

@@ -11,14 +11,9 @@
## 依赖
* bash
* coreutils
* curl
* openssl
## 注意事项
由于 URL 编码使用了 `curl``--data-urlencode` 实现,所以每次 URL 编码都会对本地的 65535 端口发起 HTTP 请求,如果你的 65535 端口不是空闲的,为了避免对你的服务造成影响,建议修改脚本的 `_urlencode` 函数。
## 使用
1. 导出环境变量 `AliAccessKeyId``AliAccessKeySecret`
@@ -27,7 +22,7 @@
函数签名:
```
aliapi_rpc(host, http_method, api_version, api_action, api_custom_key[], api_custom_value[]): JsonResult | ErrorCode
aliapi_rpc(host, http_method, api_version, api_action, api_custom_key[], api_custom_value[]): JsonResult
```
**示例:**
@@ -61,8 +56,8 @@ api_custom_value=(
)
# 获取 SSL 证书列表https://help.aliyun.com/document_detail/126511.html
aliapi_rpc "cas.aliyuncs.com" "GET" "2018-07-13" "DescribeUserCertificateList" "${api_custom_key[*]}" "${api_custom_value[*]}"
# $? (返回代码) 等于 0 (HTTP 状态码 == 200) 代表执行成功
# 执行成功返回 JSON 数据,执行失败返回 HTTP 状态码或 curl 的错误代码 ($?)。
# $? == 0 代表 HTTP CODE == 200 反之 $? == 1
# 只要 curl 的返回代码 == 0 就会返回接收到的数据
if [[ $? -eq 0 ]]; then
# 执行成功
else