【发布时间】:2017-01-02 19:59:10
【问题描述】:
我的 Angular 2 应用程序遇到了一个非常奇怪的问题。我实际上想对我的 Play Scala API 进行包含 JSON 的 POST 调用,但它一直想尝试进行 OPTIONS 调用。
这是我的代码:
登录服务
constructor (private _apiEndpoint: ApiEndpoint) {}
postLogin(login: string, credential: string): Observable<AuthToken> {
let headers = new Headers({ "Content-Type": "application/json" })
let jsonLogin = {"login": login, "password": credential}
return this._apiEndpoint.postLogin(JSON.stringify(jsonLogin), headers)
.map(this._apiEndpoint.extractData)
}
ApiEndpoint
constructor (private _http: Http) {}
postLogin(body: string, options: any) {
return this._http.post("http://localhost:9000/login", body, {
headers: options
})
}
然后当我尝试拨打电话时(我尝试通过 console.log 检查 JSON 并且它是正确的),并且无论出于何种原因,该电话都会尝试拨打 OPTIONS 电话:
有人知道吗?谢谢!
【问题讨论】:
标签: angular