如何读取 deno 上的请求数据
how do I read the request data on deno
如何读取 deno 上 post 请求的请求数据?我在请求对象中找不到任何东西
for await (const req of s) {
// ^ that req object
if(req.url === '/update' && method == 'POST') console.log(req) // this is where I need the data
}
我不确定你是否真的使用了正确的库,但这是它工作的一个例子:
import { serve } from "https://deno.land/std@0.103.0/http/server.ts";
import { readAll } from "https://deno.land/std@0.103.0/io/util.ts";
const server = serve({ port: 8080 });
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
for await (const req of server) {
if (req.url === "/update" && req.method === "POST") {
console.log("Body:", new TextDecoder().decode(await readAll(req.body)));
}
req.respond({ status: 200, body: "Welcome to my server" });
}
如何读取 deno 上 post 请求的请求数据?我在请求对象中找不到任何东西
for await (const req of s) {
// ^ that req object
if(req.url === '/update' && method == 'POST') console.log(req) // this is where I need the data
}
我不确定你是否真的使用了正确的库,但这是它工作的一个例子:
import { serve } from "https://deno.land/std@0.103.0/http/server.ts";
import { readAll } from "https://deno.land/std@0.103.0/io/util.ts";
const server = serve({ port: 8080 });
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
for await (const req of server) {
if (req.url === "/update" && req.method === "POST") {
console.log("Body:", new TextDecoder().decode(await readAll(req.body)));
}
req.respond({ status: 200, body: "Welcome to my server" });
}