+ 1

How to allow POST method on the VsCode live server

I'm making a simple website and writing code in the vscode program an error pops up when trying to send a post request POST http://127.0.0.1:5501 / net::ERROR_ABORTED 405 (Method Not Allowed)short in the Devtools tool, you can see that POST is not allowed, but only GET is available what should I do to allow the server to POST requests

12th Apr 2024, 9:50 AM
Pit
4 ответов
+ 2
VS Code Live Server does not support PHP, or any form of server side programming, and will give 405 errors for POST requests. You need to switch to an HTTP server that supports PHP. https://www.php.net/manual/en/tutorial.requirements.php To run a local PHP server. Install and run XAMPP: https://stackoverflow.com/questions/1678010/php-server-on-local-machine
12th Apr 2024, 11:52 PM
Chris Coder
Chris Coder - avatar
+ 1
To allow POST method on the VS Code Live Server, you need to configure CORS (Cross-Origin Resource Sharing) settings properly. This ensures that different domains can communicate with your server using methods like POST. In your server code, set the appropriate headers to allow POST requests from any domain. Additionally, make sure your form submission or AJAX request specifies the correct method as POST. With these tweaks, you'll be able to send POST requests smoothly and process data accordingly.
12th Apr 2024, 12:37 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
0
const express = require('express'); const bodyParser = require('body-parser'); const app = express(); const PORT = 3000; app.use(bodyParser.json()); app.post('/submit-form', (req, res) => { console.log('Received POST request:', req.body); res.send('POST request received!'); }); app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); });
14th Apr 2024, 2:43 AM
Vidhya Tharan
Vidhya Tharan - avatar
0
You can also try json-server: https://github.com/typicode/json-server If you have node.js installed, you can quickly run: npx json-server db.json
24th Jul 2024, 7:58 AM
Kostas Minaidis
Kostas Minaidis - avatar