Closed johndiego closed 4 years ago
How is your application deployed? Do you have any proxy layers in front of it?
in Frontend
<script>
import axios from 'axios'
export default {
name: 'PageIndex',
methods: {
login: function () {
let postData = {
username:'master',
password: 'Password@1'
};
axios.post('http://172.21.0.4/users/1/', postData )
.then((res) => {
console.log(res)
})
.catch(function (error) {
console.log(error)
})
.finally(function () {
})
}
},
}
</script>
I think you need https://pypi.org/project/Sanic-Cors/ to respond to OPTIONS requests correctly. If the browser doesn't know of CORS status, it won't run you POST request directly but first checks for the headers, and without Sanic CORS extension (or handling OPTIONS manually) it will get 404 instead.
how make handling OPTIONS manually?
Take a look at my answer to your question on #1759. I think this is what you need.
OP's issue, not the header part, but the Sanic server not seeing the postData
, might be related to the discussion here (I have the same issue): https://community.sanicframework.org/t/sanic-cant-recognize-post-request/498
Seems like Sanic cannot handle JSON formatted data, as opposed to url-based keywords?
Sanic has no problem with query params or JSON data. Please see my response to your post.
My code don't work with axios and vuejs , This is correct implementations? I like'd make without libs !! Thanks for advanced !!
In console