gpt4 book ai didi

angular4 http headers,如何设置?

转载 作者:行者123 更新时间:2023-12-02 20:54:58 25 4
gpt4 key购买 nike

import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions, } from '@angular/http';
@Injectable()
export class RoleService {
headers = new Headers({"Content-Type": "application/json"});
options = new RequestOptions({ headers: this.headers });
constructor(private http: Http) { }

getRoleList(data) {
return this.http.post('http://192.168.10.178:9080/role/getRole', data, this.options)
.toPromise()
.then(res => res.json().data)
.then(data => { return data; });
}
}

/image/nPiK8.png

帮帮我!!怎么解决这个问题???

最佳答案

尝试

export class RoleService {
options: RequestOptions;

constructor(private http: Http) {
let headers: any = new Headers();
headers.append('Content-Type', 'application/json');

this.options = new RequestOptions({ headers: headers });
}

// ........

关于angular4 http headers,如何设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45345550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com