使用ng2发布时$ _php ['creds']为空

时间:2017-03-17 09:50:58

标签: php rest angular

对于ng2 restful webservice,

$_post['creds']为空:

let creds  = "email=" + userDetails.email + "&password=" + userDetails.password;
    let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
    let options = new RequestOptions({ headers: headers });
     this.http.post("http://www.dr-gontar.com/checkSignIn/", creds, options)
        .subscribe((data:Response) => this.id = JSON.parse(data.text()).id);

this.http.post("http://www.dr-gontar.com/checkSignIn/", creds, options )
    .subscribe((data:Response) => this.email = JSON.parse(data.text()).email);

this.http.post("http://www.dr-gontar.com/checkSignIn/", creds, options )
    .subscribe((data:Response) => this.name = JSON.parse(data.text()).name);

this.http.post("http://www.dr-gontar.com/checkSignIn/", creds, options)
    .subscribe((data:Response) => this.mobile = JSON.parse(data.text()).mobile);

this.http.post("http://www.dr-gontar.com/checkSignIn/", creds, options )
    .subscribe((data:Response) => this.address = JSON.parse(data.text()).address);

this.userDetails = [this.id,this.email,this.name,this.mobile,this.address];
console.log(this.userDetails);

1 个答案:

答案 0 :(得分:0)

使用URLSearchParams

sendUserAndPass(userDetails) {
  let body = new URLSearchParams();
  body.set('email', userDetails.email);
  body.set('password', userDetails.password)

  let headers = new Headers();
  headers.append('Content-Type', 'application/x-www-form-urlencoded');
  let options = new RequestOptions({ headers: headers });

  this.http.post('url', body.toString(), options)
    .map(res => res.json())
    .subscribe(data => console.log(data))
}

然后你就可以得到你的电子邮件:

$_POST['email']