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.在上面我们确实请求了,koa2的request能对其处理,接受了一些信息,但是不利于对数据的处理.
    为此有ctx直接调用的情况,下面学习ctx.request中的直接操作.

    3.ctx.header 请求信息

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

    4.很有趣,直接拿到的是 ctx.request.header.这对我们开发来说非常的方便和编写.

    5.ctx.headers 请求信息

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

    6.ctx.headers和ctx.header测试的时候发现一样,有不同的地方吗?