Evan Hu
Evan Hu

Reputation: 60

angular2 http post request get a error

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());
  }
}

Upvotes: 0

Views: 251

Answers (1)

Yassmeen Mahmoud
Yassmeen Mahmoud

Reputation: 43

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

Upvotes: 1

Related Questions