Request.text() is not work !
Answered
Indian oil sardine posted this in #help-forum
Indian oil sardineOP
I use stripe webhook. I need to verify the correct incoming. so I follow Requst.text() from
Office document. but get error:
Office document. but get error:
⨯ TypeError: Body is unusable
at specConsumeBody (node:internal/deps/undici/undici:5384:15)
at NextRequest.text (node:internal/deps/undici/undici:5283:18)
at POST (webpack-internal:///(rsc)/./app/api/webhook/stripe/route.ts:19:35)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async E:\youtube_javascriptmastery_project\evently\evently\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:63251export async function POST(request: Request) {
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET!
// console.log("stripe---req---", req);
// console.log("request", request);
const reqJson = await request.json()
const reqJsonStr = JSON.stringify(reqJson)
// const reqFormData = await request.formData()
const reqText = await request.text()
const reqBody = request.body
console.log("---------------stripe------req.json()------------------------");
console.log(reqJson);
console.log("---------------stripe------req.JSON.stringify(reqJson)------------------------");
console.log(reqJsonStr);
// console.log("---------------stripe------req.reqFormData()------------------------");
// console.log(reqFormData);
console.log("---------------stripe------req.text()------------------------");
console.log(reqText);Answered by joulev
you can only call
request.json, request.formData and request.text once in total. so once you have called request.json, you can no longer call request.text2 Replies
Indian oil sardineOP
It's solved. trank you