angular2标头未正确设置
在 reaction.service.ts 文件中我尝试了设置X-Comma-Sep-Arrays: true
标头。如果我在chrome中检查devTools,我会看到Access-Control-Request-Headers:x-comma-sep-arrays
和Accept:*/*
。 screen shot
在控制台中我也遇到this错误
import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions } from '@angular/http';
import 'rxjs/Rx';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class ReactionService {
constructor(private http: Http) { }
getReaction(ruid) {
const headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append('Accept', 'application/json');
headers.append('X-Comma-Sep-Arrays', 'true' );
const body = 'ruid=' + ruid;
const options = new RequestOptions({ headers: headers, withCredentials: true });
return this.http.post('https://serverURL', body, options).map(
(response: Response) => {
const data = response.json();
console.log(data);
return data;
}
).catch(
(error: Response) => {
console.log(error);
return Observable.throw(error);
});
}
}