Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm stuck on something. I test my api from chome postman app with requests like:

http://localhost:50000/api/user/user_name/machines

and it works. I started building front end in vue.js and try the following:

getReports() {
    this.$http
      .get('http://localhost:50000/api/user/user_name/machines', (data) => {
        this.data = data;
      })
      .error((err) => console.log(err))
  }

and of course i get

XMLHttpRequest cannot load http://localhost:50000/api/user/user_name/machines. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

I previously try some react.js and came across same problem so like then i just added

services.AddCors();

and

app.UseCors(builder => builder.AllowAnyOrigin());

to my startup.cs file but no luck this time. I remember it worked on react.js. I can also get data directly from the browser - just by going to this url. Why vue.js has problems?

my startup.cs file: http://pastebin.pl/view/b93c9e2c

share|improve this question
    
it works when I delete: Vue.http.headers.common['Authorization'] = 'Bearer ' + localStorage.getItem('id_token'); but why header is thee problem? A also add builder.AllowAnyHeader(); but it didn't help – lukpep Apr 30 at 7:41

You're running into a Cross Origin Request (cors) limitations. This usually happens when you are using fully qualified url when making a server request that is a different origin than the hosting document.

In your example you are using http://localhost:50000/api/user/user_name/machines in your request. If possible you can use a relative path like /api/user/user_name/machines instead so the request will be made based on the url entered in the browser. This will make sure the browser doesn't send a preflight request.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.