简体   繁体   English

$ _POST中没有任何内容(Http请求/ Angular / PHP)

[英]Nothing in $_POST (Http request / Angular / PHP)

I'm stuck with a simple issue, but I did not find any answer on Web. 我遇到一个简单的问题,但是在Web上找不到任何答案。 So, here is my code 所以,这是我的代码

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 ! ");
    }
  );
}

But in my file 'Fiabilisation_Unique.php", when I try a simple : print_r($_POST); it prints me : Array( ) 但是在我的文件“ Fiabilisation_Unique.php”中,当我尝试一个简单的: print_r($_POST);它会向我输出: Array( )

I am pretty sure that my problem is not that complicate but I just don't figure out what is the issue. 我很确定我的问题不会那么复杂,但是我只是不知道问题出在哪里。 I also know that answer should not be that far but... 我也知道答案不应该那么远,但是...

Thank you in advance :) 先感谢您 :)

Your HttpOptions are not correct. 您的HttpOptions不正确。 Wrong quotation and reportProgress is misplaced: 引号错误和reportProgress放错了位置:

const httpOptions = {
  headers: new HttpHeaders({
   'Content-Type': 'application/json'
  },
  reportProgress: true
});

But if you enable the reportProgress , the subscribe will receive multiple events from HttpEventType.Sent to HttpEventType.Done . 但是,如果启用reportProgress ,则订阅将从HttpEventType.Sent发送到HttpEventType.Done接收多个事件。 But I guess that is what you want :) 但是我想这就是你想要的:)

Ok Everyone, I finally found the answer. 好的,大家,我终于找到了答案。 As expected, It was really easy. 不出所料,这真的很容易。

I just add a $angularJSData = json_decode(file_get_contents("php://input")); 我只添加一个$angularJSData = json_decode(file_get_contents("php://input")); in my PHP code. 在我的PHP代码中。

Thanks everyone ! 感谢大家 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM