我正在嘗試從 Postman 的 POST 請求中獲取 JSON,但是我無法訪問該資訊,只能找到未找到的路線。我知道端點很好,因為 get 請求作業正常。我正在嘗試在沒有框架的情況下完成請求。感謝您的任何想法。
const server = http.createServer(async (req, res) => {
res.statusCode = 200;
// Crete an autor
} else if (req.url === '/api/authors' && req.method === 'POST') {
const server = http.createServer((req, res) => {
req.on('data', (chunk) => {
console.log(`Data chunk available: ${chunk}`);
});
req.on('end', () => {});
});
} else {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'Route Not Found' }));
}
uj5u.com熱心網友回復:
您的代碼結構不正確,請參閱以下鏈接以了解如何處理 post 方法:
https://www.pabbly.com/tutorials/node-js-http-server-handling-get-and-post-request/
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/321500.html
