【发布时间】:2017-10-10 13:12:23
【问题描述】:
Angular 4.4.4
这是我的应用组件
constructor(
private http: HttpClient,
)
this.http.post('/api.php', {name, age}).subscribe(data => {
console.log(data);
});
api.php -> exit(json_encode($_POST));
$_POST 中不接收任何数据
返回 [];
(let xmlRequest = new XMLHttpRequest();
……
工作正常)
我尝试设置标题
let headers = new HttpHeaders().set('Content-Type', 'application/json; charset=UTF-8');
不工作
很抱歉这个问题,但我花了 1 天时间仍然找不到解决方案。
ps。客户端和服务器同源。
【问题讨论】:
-
请发布您的 PHP 方法
-
退出(json_encode($_POST))
-
我的意思是,你的签名,你的方法
标签: php angular post httpclient