matthew-andrews / isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify
MIT License
6.95k stars 289 forks source link

405: Method Not Allowed #134

Closed charleylla closed 7 years ago

charleylla commented 7 years ago

when I open a post request, it doesn't work well, what's wrong with my code? p.s. get method works well.

try{
    const URL = config.LOGIN;
    const data = await fetch(URL,{
        method:"POST",
        headers:{
            "Accept": "application/json",
            "Content-Type": "application/json"
        },
        body:JSON.stringify({
            "a":1,
            "b":2
        })
    }).then((response)=>{
        return response.json();
    });

    console.log(data)
}catch(e){
    alert(e)
}

and browser reports an error: 405: Method Not Allowed

get request works fine

const data = await fetch(URL).then((res)=>{
    return res.json()
});

Thanks!

jackfranklin commented 7 years ago

@charleylla you're better off posting this to StackOverflow - this isn't a bug with this module but probably one with your API or your JS - and this probably isn't the best environment for help on things like that :)

charleylla commented 7 years ago

thanks