0

XMLHttpRequest cannot load http://localhost:8080/adminUser/login. Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

error_handler.js:48 EXCEPTION: Response with status: 0 for URL: null

server has supported CORS...but I still get this.

the code

import {Injectable} from "@angular/core";
import {Http, Headers} from "@angular/http";
import { getUserApi } from "../../../api.config";

@Injectable()
export class UserService {

  constructor(public http: Http) {
  }

  login(userName, password) {
    return this.http.post(getUserApi, {userName: userName, password:password})
      .map(res => res.json());
  }
}
4
  • Looks like getUserApi is null or undefined Commented Oct 29, 2016 at 9:38
  • I am sure getUserApi is not null. because I console.log it Commented Oct 29, 2016 at 9:43
  • Where you log it? Commented Oct 29, 2016 at 10:05
  • XMLHttpRequest cannot load localhost:8080/adminUser/login. Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response. Commented Oct 31, 2016 at 1:41

1 Answer 1

1

The header of 'Access-Control-Allow-Origin': '*' should be in the server response headers not in the request header.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.