1

I've created a JS webpage that sends the student's authentication information and the ID to take the course, but when I make a POST request to the FastAPI server, it returns a 405 Method Not Allowed error.

Below is the code I tried:

[index.js]

const countia = String(count)
const celestia = String(core)
const dataToSend = {
    stdid: stdid,
    stdpw: stdpw,
    stdmail: stdmail,
    countia: countia,
    celestia: celestia
};
fetch("/api/data", {
    method: "POST",
    headers: {
    'Accept': 'application/json',
    "Content-Type": "application/json"
    },
    body: JSON.stringify(dataToSend)
})
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error(error));

All strings are characters, no problem ( maybe )

[server.py]

class directa(BaseModel):
    stdid: str
    stdpw: str
    stdmail: str
    countia: str
    celestia: str

class dataToSend(BaseModel):
    dataToSend: str

@app.post("/api/data")
async def receive_data(Directa: directa):
    print(Directa)
    return {"message": "Data received", "data": dataToSend}
Chris
  • 18,724
  • 6
  • 46
  • 80
AR_IO
  • 33
  • 4
  • Related answers can also be found [here](https://stackoverflow.com/a/73761724/17865804) and [here](https://stackoverflow.com/a/70636163/17865804) – Chris Mar 04 '23 at 06:14
  • Sorry, my mistake in question i not using any form tag on my html and i trying CORS Add + rewriting send code & question other community but result .. um.. i cant fix it, – AR_IO Mar 04 '23 at 07:16
  • Thank you Chris i will be trying other backend or check framework version, i use stackoverflow Third time and i think i need more study and studying english.. i say twice , thank you! – AR_IO Mar 04 '23 at 07:18

0 Answers0