aardio 文档
aardio 范例:设置 HTTP 头
//设置 HTTP 头
import crypt;
import web.rest.jsonLiteClient;
var http = web.rest.jsonLiteClient();
//如果所有请求都要添加的相同HTTP头,在这里指定
http.setHeaders(
["Test"] = "test"
)
/*
如果每次请求都要修改HTTP头,可以写到这个事件里.
*/
http.beforeRequestHeaders = function(params){
var apiKey = "";
var secretKey = "";
var authorization = {
["apiKey"] = apiKey;
["time"] = tonumber(time());
}
authorization["sign"] = crypt.md5(apiKey ++ secretKey ++ authorization.time)
//通过返回值设置本次请求的HTTP头, Content-Type不需要指定(会自动指定)
return {
["Authorization"] = crypt.encodeBin(web.json.stringify(authorization))
};
}
var api = http.api("http://httpbin.org/anything");
var jsonData = api.post({
用户名 = "用户名";
密码 = "密码";
})
import console;
console.dumpJson(jsonData)
console.pause(true);
Markdown 格式