Answer the question
In order to leave comments, you need to log in
Why do post requests fail, but GET requests do?
Probably a boring question, but I'm at an impasse.
There is a remote test server on debian, NGINX is configured on it, which proxies the necessary requests to the local node express server service (not docker).
One server on localhost:3001 to work with the database, everything is fine here, all REST requests go through (POST, GET ....).
And the second one on localhost:3002 for uploading images. Here I have a problem with CORS
Error in the browser (Local page on VUE (npm run serve) with axios requests)
Access to XMLHttpRequest at ' https://myTestServer/uploadImg ' from origin ' localhost:8080 ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
next();
});
app.use(cors())
"OPTIONS /uploadImg HTTP/1.1" 301 169 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36" "-"
Answer the question
In order to leave comments, you need to log in
Found the problem.
From the client, I sent requests to
' https://myTestServer/uploadImg 'so I get an error
https://mytestserver/uploadimg/this is how it works
app.post('/uploadImg', async(req, res) => {
location /uploadimg/although it is strange, since the first service with requests without a slash at the end works ... files are not accepted there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question