0
votes

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());
  }
}
1
Looks like getUserApi is null or undefinedJens
I am sure getUserApi is not null. because I console.log itHu Peng
Where you log it?Jens
XMLHttpRequest cannot load localhost:8080/adminUser/login. Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.Hu Peng

1 Answers

1
votes

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