angular - $_POST 中没有任何内容(Http 请求/Angular/PHP)
问题描述
我遇到了一个简单的问题,但我在网上没有找到任何答案。所以,这是我的代码
const URL = 'http://(...)/scripts/Fiabilisation_Unique.php';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type: application/json'
'reportProgress': 'true'
})
(...)
onClickAdresse(f : NgForm){
var adresse : Adresse= (f.value);
console.log(adresse); //{adresse : "just a french adresse"}
this.http.post(URL, adresse, httpOptions).subscribe(
(event) => {
this.temp=(event); // handle event here
},
() => {
console.log("Observable done ! ");
}
);
}
但是在我的文件“Fiabilisation_Unique.php”中,当我尝试一个简单的:print_r($_POST);
它打印我:Array(
)
我很确定我的问题并不复杂,但我只是不知道问题出在哪里。我也知道答案不应该那么远,但是......
先感谢您 :)
解决方案
你HttpOptions
的不正确。错误的引用和reportProgress 放错了位置:
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
},
reportProgress: true
});
但是如果你启用reportProgress
,订阅将收到来自HttpEventType.Sent
to的多个事件HttpEventType.Done
。但我想这就是你想要的:)
推荐阅读
- vue.js - 字体真棒无法与 vue cli 3 一起正常工作
- security - 同源政策很容易被规避?
- javascript - 节点JS | 谷歌视觉 API | 将 base64 发送到 Google Cloud Vision 时出现“错误的图像数据”
- python - 只收到一条消息然后断开连接(Telethon)
- python - 为什么 Python dict 具有属性状态但点运算符不起作用?
- applescript - 如何在applescript工作期间显示对话框窗口
- javascript - 我想将空值替换为字符串并更改 javascript 数组中的小数点
- postgresql - 用于 JOIN 查询的 Postgresql 分页性能
- python - 带逗号的切片符号,Numpy - Python
- r - 如何在 tbl_summary 中使用 by = 参数进行有序排序?