'Error 405 when making a request to locally hosted webserivce from local site

I currently have a flask API and website (hosted locally using nodejs), which down the line I'm going to separate. The issue I'm having is that when I make a request from the website to my local API, it gives me a 405 Method Not Allowed error. I tried doing the request through Postman and it went through. I've also tried disabling CORS, which gave the same error.

API-side:

@app.route("/api/CreateToken", methods=['POST'])
def createToken():
    print(request.form['tokenJson'])
    return "added token successfully."

Website-side:

function test() {
    var formdata = new FormData();
    formdata.append("tokenJson", "Long string that gets processed in the API");
    var requestOptions = {
        method: 'POST',
        mode: "no-cors",
        body: formdata,
        redirect: 'follow'
    };
    console.log("Sending Token")
    fetch("192.168.0.xxx:5000/api/CreateToken", requestOptions)
        .then(response => response.text())
        .then(result => console.log(result))
        .catch(error => console.log('error', error));
}
document.addEventListener('DOMContentLoaded', (event) => {test();});


Solution 1:[1]

Turns out the issue was that it was going to 192.168.0.xxx:8080/192.168.0.xxx:5000/api/CreateToken because I forgot to put http:// in front of the IP of the request.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yangsibai