Angular2自定义标头未正确设置

时间:2017-10-19 18:11:24

标签: javascript angular angular-services angular-http

angular2标头未正确设置

reaction.service.ts 文件中

我尝试了设置X-Comma-Sep-Arrays: true标头。如果我在chrome中检查devTools,我会看到Access-Control-Request-Headers:x-comma-sep-arraysAccept:*/*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);
            });
    }
}




0 个答案:

没有答案