next的路由无法获取请求的body?

nextjs请求的为json object stream方式,这是一种流的方式传输,需要用await等待一下,或是then

js 复制代码
import { NextRequest, NextResponse } from "next/server";
// export const dynamic = 'force-dynamic' // defaults to auto
export async function POST(request: NextRequest) {
  const body = await request.json();
  console.log(body);
    return new Response(JSON.stringify({ a:1, b:2 }), {
        headers: { 'Content-Type': 'text/plain' },
    })
}
export async function GET(request: Request) {

    console.log(request.headers.get('cookie'));
    return new Response(JSON.stringify({ c:3, d:4 }), {
        headers: { 'Content-Type': 'text/plain',"set-cookie":'token=1234567890;path=/;HttpOnly;SameSite=Lax' },
    })
}

如果直接用postman,nextjs是直接报500,这里需要稍微注意一下改成以下

相关推荐
unable code21 小时前
浏览器取证-[GKCTF 2021]FireFox Forensics
网络安全·ctf·misc·1024程序员节·浏览器取证
unable code1 天前
内存取证-[安洵杯 2019]Attack
网络安全·ctf·misc·1024程序员节·内存取证
unable code2 天前
CTF-SPCS-Forensics
网络安全·ctf·misc·1024程序员节·取证
unable code3 天前
内存取证-卡比卡比卡比
网络安全·ctf·misc·1024程序员节·内存取证
学传打活3 天前
【边打字.边学昆仑正义文化】_3_宇宙人类演化史(2)
微信公众平台·1024程序员节·汉字·昆伦正义文化
unable code3 天前
内存取证-Stager
网络安全·ctf·misc·1024程序员节·内存取证
开开心心就好4 天前
轻松加密文件生成exe,无需原程序解密
linux·运维·服务器·windows·pdf·harmonyos·1024程序员节
unable code4 天前
内存取证-easy_mem_3
网络安全·ctf·misc·1024程序员节·内存取证
开开心心就好4 天前
高效U盘容量检测工具,一键辨真假,防假货
linux·运维·服务器·线性代数·安全·抽象代数·1024程序员节
unable code4 天前
内存取证-easy_mem_2
网络安全·ctf·misc·1024程序员节·内存取证