缺少参数:电子邮件,在 angular4 中发布数据时出现密码错误?
Missing parameter(s): email, password error is occurring on posting data in angular4?
我是 angular 4 的新手。我正在处理登录页面,我必须在其中 post login.But 上的用户信息 我收到错误消息
"code":"rest_missing_callback_param","message":"Missing parameter(s): email, password" 在 post 上 data.Below 是我的代码:
import { Component, OnInit } from '@angular/core';
import {Http,Response,Headers, RequestOptions} from '@angular/http';
import { Router} from '@angular/router';
import { NgForm } from '@angular/forms';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {
constructor(private http:Http,private router:Router) { }
login(){
this.router.navigate(['login']);
}
createAuthorizationHeader(headers: Headers) {
headers.append('Authorization', 'Basic ' +
btoa('ck_543700d9f8c08268d75d3efefb302df4fad70a8f:cs_f1514261bbe154d662eb5053880d40518367c901'));
headers.append("Content-Type", "application/x-www-form-urlencoded");
}
onSubmit(userForm:NgForm){
console.log(userForm.value);
let headers=new Headers();
this.createAuthorizationHeader(headers);
const body={
"email": userForm.value.email,
"first_name": userForm.value.fname,
"last_name": userForm.value.lname,
"username": userForm.value.uname,
"password": userForm.value.password
}
console.log(body);
console.log(headers);
this.http.post('https://www.colourssoftware.com/wordpress/wp-json/wc/v2/customers',body,{
headers:headers
})
.subscribe(
data => {
console.log(data);
},
err => {
console.log("ERROR!: ", err);
}
);
}
ngOnInit() {
}
}
<form class="animated wow slideInUp" data-wow-delay=".5s" #regForm="ngForm" (ngSubmit)="onSubmit(regForm)">
<input type="text" placeholder="First Name..." required=" " name="fname" ngModel>
<input type="text" placeholder="Last Name..." required=" " name="lname" ngModel>
<input type="text" placeholder="UserName..." required=" " name="uname" ngModel>
<h6 class="animated wow slideInUp" data-wow-delay=".5s">Login information</h6>
<input type="email" placeholder="Email Address" required=" " name="email" ngModel>
<input type="password" placeholder="Password" required=" " name="password" ngModel>
<div class="register-check-box">
<div class="check">
<label class="checkbox"><input type="checkbox" name="checkbox"><i> </i>I accept the terms and conditions</label>
</div>
</div>
<input type="submit" value="Register">
</form>
我哪里做错了?我怎样才能把post的数据传到服务器angular 4?请帮助我。
在您的提交方法中,您正在形成一个 JSON object,但您将其作为 application/x-www-form-urlencoded
发送。我的猜测是您应该将 headers 设置为 application/json
。
我知道这是一个很老的问题,但我回答这个问题是为了让其他人受益。
> You should use yoursite.com/wordpress/wp-json/wc/v2/users API instead
> of yoursite.com/wordpress/wp-json/wc/v2/customers
在验证用户登录或使用 WordPress 注册客户时休息 API。
另外,请确保您在 header.
中设置了有效授权
*** 如果您想使用您的网站。com/wordpress/wp-json/wc/v2/customers API 那么您必须在 WordPress 中拥有具有相同 username/password 的客户帐户,然后只有您才能验证作为 woocommerce 的客户 api
我是 angular 4 的新手。我正在处理登录页面,我必须在其中 post login.But 上的用户信息 我收到错误消息 "code":"rest_missing_callback_param","message":"Missing parameter(s): email, password" 在 post 上 data.Below 是我的代码:
import { Component, OnInit } from '@angular/core';
import {Http,Response,Headers, RequestOptions} from '@angular/http';
import { Router} from '@angular/router';
import { NgForm } from '@angular/forms';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {
constructor(private http:Http,private router:Router) { }
login(){
this.router.navigate(['login']);
}
createAuthorizationHeader(headers: Headers) {
headers.append('Authorization', 'Basic ' +
btoa('ck_543700d9f8c08268d75d3efefb302df4fad70a8f:cs_f1514261bbe154d662eb5053880d40518367c901'));
headers.append("Content-Type", "application/x-www-form-urlencoded");
}
onSubmit(userForm:NgForm){
console.log(userForm.value);
let headers=new Headers();
this.createAuthorizationHeader(headers);
const body={
"email": userForm.value.email,
"first_name": userForm.value.fname,
"last_name": userForm.value.lname,
"username": userForm.value.uname,
"password": userForm.value.password
}
console.log(body);
console.log(headers);
this.http.post('https://www.colourssoftware.com/wordpress/wp-json/wc/v2/customers',body,{
headers:headers
})
.subscribe(
data => {
console.log(data);
},
err => {
console.log("ERROR!: ", err);
}
);
}
ngOnInit() {
}
}
<form class="animated wow slideInUp" data-wow-delay=".5s" #regForm="ngForm" (ngSubmit)="onSubmit(regForm)">
<input type="text" placeholder="First Name..." required=" " name="fname" ngModel>
<input type="text" placeholder="Last Name..." required=" " name="lname" ngModel>
<input type="text" placeholder="UserName..." required=" " name="uname" ngModel>
<h6 class="animated wow slideInUp" data-wow-delay=".5s">Login information</h6>
<input type="email" placeholder="Email Address" required=" " name="email" ngModel>
<input type="password" placeholder="Password" required=" " name="password" ngModel>
<div class="register-check-box">
<div class="check">
<label class="checkbox"><input type="checkbox" name="checkbox"><i> </i>I accept the terms and conditions</label>
</div>
</div>
<input type="submit" value="Register">
</form>
我哪里做错了?我怎样才能把post的数据传到服务器angular 4?请帮助我。
在您的提交方法中,您正在形成一个 JSON object,但您将其作为 application/x-www-form-urlencoded
发送。我的猜测是您应该将 headers 设置为 application/json
。
我知道这是一个很老的问题,但我回答这个问题是为了让其他人受益。
> You should use yoursite.com/wordpress/wp-json/wc/v2/users API instead
> of yoursite.com/wordpress/wp-json/wc/v2/customers
在验证用户登录或使用 WordPress 注册客户时休息 API。 另外,请确保您在 header.
中设置了有效授权*** 如果您想使用您的网站。com/wordpress/wp-json/wc/v2/customers API 那么您必须在 WordPress 中拥有具有相同 username/password 的客户帐户,然后只有您才能验证作为 woocommerce 的客户 api