1.请求(ctx.request)的信息
{
method: "GET",
url: "/",
header: {
host: "localhost:3000",
connection: "keep-alive",
cache-control: "max-age=0",
upgrade-insecure-requests: "1",
user-agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
accept-encoding: "gzip, deflate, br",
accept-language: "zh-CN,zh;q=0.9,en;q=0.8"
}
}
2.请求参数对象(ctx.query)
a.针对上章的问题,假设 http://localhost:3000/inde.php?username=ziye&pwd=123456 通过ctx.url拿到如下,但是在操作数据上有些欠缺,而ctx.query就很好的处理这个问题.
/inde.html?username=ziye&pwd=123456
再次请求 http://localhost:3000/inde.php?username=ziye&pwd=123456, ctx.query测试结果如下
{
username: "ziye",
pwd: "123456"
}
3.所以我建议用 ctx.query拿到get请求过来的数据.
4.同样ctx.querystring也是拿到参数的,但是拿到的参数是字符串,可以看出是在?号之后截取的字符串,当然在这种情况很难直接转为json对象.
username=ziye&pwd=123456