Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctx.request.body is not a function #652

Closed
jiaozaolan opened this issue Apr 25, 2024 · 0 comments
Closed

ctx.request.body is not a function #652

jiaozaolan opened this issue Apr 25, 2024 · 0 comments
Labels
duplicate This issue or pull request already exists unactionable There is no logical action to take with this issue

Comments

@jiaozaolan
Copy link

jiaozaolan commented Apr 25, 2024

This is my code

import { Router } from "https://deno.land/x/oak/mod.ts";
const router = new Router();

router
.post("/example", async (ctx) => {
  const contentType = ctx.request.headers.get("Content-Type");

  if (contentType && contentType.includes("application/json")) {
    const body = await ctx.request.body({ type: "json" }).value;
    // 在这里可以访问到解析后的 JSON 数据
    console.log(body);
    ctx.response.body = "Received JSON data";
  } else if (contentType && contentType.includes("application/x-www-form-urlencoded")) {
    const body = await ctx.request.body({ type: "form" }).value;
    // 在这里可以访问到解析后的表单数据
    console.log(body);
    ctx.response.body = "Received form data";
  } else {
    ctx.response.body = "Unsupported Media Type";
  }
});
export default router;

The deno version is 1.42.1

@kitsonk kitsonk closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2024
@kitsonk kitsonk added duplicate This issue or pull request already exists unactionable There is no logical action to take with this issue labels Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists unactionable There is no logical action to take with this issue
Projects
None yet
Development

No branches or pull requests

2 participants