-1
POST、PUT、またはDELETEリクエストを実行すると、2つのhttpコール が最初のリクエストメソッド:オプションと2番目のリクエストメソッド(ステータスコード:500)を使用します。 PS: GETメソッド。 がIonic2 Angular2 HTTPエラー
@Injectable()
export class UtilisateurService {
url:string;
_http:Http;
headers:Headers;
options:RequestOptions;
constructor(public http: Http) {
this._http=http;
this.url='http://localhost:8080/todo/user/';
this.headers = new Headers();
this.headers.append('Content-Type', 'application/json');
this.headers.append('Access-Control-Allow-Origin', '*');
this.headers.append('Access-Control-Allow-Methods', 'POST, GET, DELETE, PUT');
this.headers.append('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, X-Auth-Token, content-type');
this.options = new RequestOptions({ headers: this.headers })
}
addUser(user:Object): Observable<Response> {
let data = JSON.stringify(user, null, 2)
console.log('adduser '+data)
return this._http.post(this.url+'add', data,this.options).map(res => <Object> res.json())
.do(data => console.log(data))
.catch(this.handleError)
}