這是service.ts代碼。我使用服務器端REST API來驗證 用戶名和密碼。即使CORS出現在服務器端 之後,錯誤仍然存在。如果有人知道我在做什麼worng幫助我和 在此先感謝。使用Spring Boot Rest Api的Angular4中的Access-Control-Allow-Origin錯誤
import { Injectable } from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
@Injectable()
export class Service {
constructor(private http: Http) { }
authenticate(model) {
var creds = "name=" + model.email + "&password=" + model.password;
console.log(creds)
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return new Promise(resolve => {
this.http.post('http://sample.sample.com/api/authenticate', creds, {headers: headers}).subscribe(data => {
if(data.json().success){
resolve(true);
}
else
resolve(false);
});
});
}
}
向我們展示'服務器端' –