aardio 文档
aardio 范例: Cookies/inet.http
请参考 web.view 获取 Cookies
import console;
import inet.http;
var http = inet.http();
//清除指定网址的 Cookies
inet.clearCookie("httpbin.org")
/*
inet.http,web.rest,web.form 等共享会话与持久 Cookie。
在同一进程内多线程或不同的 inet.http 对象都共享会话。
inet.whttp 不会与 inet.http 等共享会话。
这些对象都是自动管理 Cookie。
inet.http 与 inet.whttp 都可以调用 disableCookies 禁用自动管理 Cookie 的功能。
web.rest.client 或继承自该对象的所有 web.rest 客户端都提供 setCookie 方法。
web.rest.client 的 setCookie 只是直接指向 inet.setCookie 函数。
*/
//写入新的 Cookie
http.get("https://httpbin.org/cookies/set/newName/newValue");
//参数指定 Cookie 对象数组,格式与与 fsys.cookies 或 CDP 返回的 Cookie 数组兼容
inet.setCookie([
{
domain = "httpbin.org";
name = "user_token";
value = "aardio_test_123";// 这种格式值必须是字符串
}
]);
/*
调用参数(网址,值,名字,过期时间)
名字或值至少要指定一个,值为空或 "delete" 删除 Cookie。
过期时间可选,传入数值时表示过期天数,指定其他非 null 值将使用 time.gmt 转换为时间。
*/
inet.setCookie( "httpbin.org","cooke_value","cooke_name"); //Cookie 值在前,名在后,不要弄反了
//仅指定一个表参数配置要添加的 Cookie 。
inet.setCookie( {
domain = "httpbin.org",
cookies = {
name1 = "value",
name2 = 123; //这种格式值可以是任意类型,自动调用 tostring 转换为 Cookie 值
}
})
//可以在参数 1 中指定支持 getCookies 方法的对象(这主要是指 web.view )
//请参考 web.view 获取 Cookies: https://www.aardio.com/zh-cn/docs/examples/WebUI/web.view/DevTools/cookies.html
inet.setCookie( {
getCookies = function(){
return [
{
domain = "httpbin.org";
name = "cdp_name";
value = "cdp_value";
}
]
}
})
// 发送 GET 请求,httpbin.org/cookies 接口会回显客户端发送的所有 Cookie
var result,err = http.get("https://httpbin.org/cookies");
//显示结果
console.status(result,"Cookies:",result,err)
console.pause();
Markdown 格式