要解决Angular Http Post发送的数据为空的问题,需要检查以下几个方面:
import { HttpClient } from '@angular/common/http';
constructor(private http: HttpClient) { }
const headers = { 'Content-Type': 'application/json' };
const data = { name: 'John', age: 30 };
this.http.post('http://example.com/api', data, { headers }).subscribe(
response => {
console.log(response);
},
error => {
console.log(error);
}
);
const data = { name: 'John', age: 30 };
const body = JSON.stringify(data);
this.http.post('http://example.com/api', body, { headers }).subscribe(
response => {
console.log(response);
},
error => {
console.log(error);
}
);
通过检查上述几个方面,应该能够解决Angular Http Post发送的数据为空的问题。