1.请求(ctx.request)的信息

    1. {
    2. method: "GET",
    3. url: "/",
    4. header: {
    5. host: "localhost:3000",
    6. connection: "keep-alive",
    7. cache-control: "max-age=0",
    8. upgrade-insecure-requests: "1",
    9. 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",
    10. accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
    11. accept-encoding: "gzip, deflate, br",
    12. accept-language: "zh-CN,zh;q=0.9,en;q=0.8"
    13. }
    14. }

    2.请求参数对象(ctx.query)
    a.针对上章的问题,假设 http://localhost:3000/inde.php?username=ziye&pwd=123456 通过ctx.url拿到如下,但是在操作数据上有些欠缺,而ctx.query就很好的处理这个问题.

    1. /inde.html?username=ziye&pwd=123456

    再次请求 http://localhost:3000/inde.php?username=ziye&pwd=123456, ctx.query测试结果如下

    1. {
    2. username: "ziye",
    3. pwd: "123456"
    4. }

    3.所以我建议用 ctx.query拿到get请求过来的数据.

    4.同样ctx.querystring也是拿到参数的,但是拿到的参数是字符串,可以看出是在?号之后截取的字符串,当然在这种情况很难直接转为json对象.

    1. username=ziye&pwd=123456