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.url)
/ //测试的时候返回的是一个斜杠,这里的url是端口号之后的信息.
3.我在浏览器中输入:ziye
4.测试 ctx.request,结果如下
{
method: "GET",
url: "/ziye", //可以发现这里加了:ziye
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"
}
}
5.比较ctx.url,在同样的请求下,结果如下
/ziye
6.知道ctx.request.url结果与ctx.url一致的,同时也知道了url指的是/之后的内容,因为/默认就存在.但这样在get请求中很难处理这个传参问题.当然koa2都处理好了,单纯的这样取请求过来的数据有些操作难度和不科学,现在来试试传入用户名和密码.
假设 http://localhost:3000/inde.php?username=ziye&pwd=123456 (不一定准确)
/inde.html?username=ziye&pwd=123456