angular 5 POST 请求出错。发送 header 参数无效
angular 5 Getting an error on POST request. Sending header param not works
我正在尝试发送 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 } );
}
但是我得到一个错误:
这里有什么问题?谁能帮我解决一下?
在我尝试其他选项后,出现了这个错误:
试试这个:
请像这样导入 HttpClient
和 HttpHeaders
:
import { HttpClient, HttpHeaders } from '@angular/common/http';
并注入你的 class:
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 });
}
我正在尝试发送 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 } );
}
但是我得到一个错误:
这里有什么问题?谁能帮我解决一下?
在我尝试其他选项后,出现了这个错误:
试试这个:
请像这样导入 HttpClient
和 HttpHeaders
:
import { HttpClient, HttpHeaders } from '@angular/common/http';
并注入你的 class:
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 });
}