Access to XMLHttpRequest has been blocked by CORS policy

后端 未结 7 2222
庸人自扰
庸人自扰 2021-02-18 16:49

I\'ve a problem when I try to do PATCH request in an angular 7 web application. In my backend I have:

app.use((re         


        
7条回答
  •  伪装坚强ぢ
    2021-02-18 17:27

    Your error:

    Access to XMLHttpRequest at 'my_url' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

    My error:

    Access to XMLHttpRequest at 'localhost:3000/api/todo' from origin 'http://localhost:4200' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

    (Even though a bit different error but i'll answer anyway)

    Now two questions here:

    1. How did i resolve my issue?

    Ans. Putting 'http://' before api i used, means 'http://localhost:3000/api/todo'.

    1. What might've caused your error?

    Ans. Can't say for sure but i dont see your api url instead it says 'my_url' (comparing both errors). I thik you may've passed string instead of variable.

    I'll be happy if this helps anyone. Because this cost me almost 2hr and now it's midnight(almost).

提交回复
热议问题