简体   繁体   English

angular2 http发布请求出错

[英]angular2 http post request get a error

XMLHttpRequest cannot load http://localhost:8080/adminUser/login . XMLHttpRequest无法加载http:// localhost:8080 / adminUser / login Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response. 在飞行前响应中,Access-Control-Allow-Headers不允许请求标头字段的内容类型。

error_handler.js:48 EXCEPTION: Response with status: 0 for URL: null error_handler.js:48例外:状态为0的URL响应:null

server has supported CORS...but I still get this. 服务器已支持CORS ...,但我仍然得到这个。

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

“ Access-Control-Allow-Origin”:“ *”的标头应位于服务器响应标头中,而不应位于请求标头中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM