I am unable to post data to strapi using next.js.
I am getting 405 Method Not Allowed.
Please Help.
Here is my code
"use client"
import { useState } from 'react';
export default function CommentPage() {
return (
<div>
<form onSubmit={handleSubmit}>
<button type="submit">Submit Comment</button>
</form>
</div>
);
}
function handleSubmit(){
try{
alert("di")
fetch('http://localhost:1337/api/save', {
//Tried using the url 'http://localhost:1337/api/saves' as well but the same error occures
method: 'post',
body: JSON.stringify({
name1: "testName",
}),
headers: new Headers({'content-type': 'application/json'}),
})
}
catch(error){
alert("error");
}
}