我正在尝试发送一个POST请求,如:
public getAppData(countryPath) : Observable<any> {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
let options = new RequestOptions({ headers: headers });
return this.http.post(this.retailApi, JSON.stringify(this.postParam), {headers: options } );
}
但我收到的错误是:
这里有什么问题?谁能帮我解决一下呢?
在我尝试使用其他选项后,我收到了此错误:
答案 0 :(得分:1)
试试这个:
请像这样导入HttpClient
和HttpHeaders
:
import { HttpClient, HttpHeaders } from '@angular/common/http';
并注入你的班级:
constructor(private http: HttpClient) {
}
和你的方法是这样的:
public getAppData(countryPath):Observable<any>{
let headers: HttpHeaders = new HttpHeaders();
headers.set('Content-Type', 'application/json');
return this.http.post(this.retailApi, JSON.stringify(this.postParam), { headers: headers });
}