在邮递员它工作:
1) url: https://app/login
2) method: POST
3) body
4) x-www-form-urlencoded
5)username: ****,
password: ****,
grant_type: 'password',
client_secret: '****',
client_id: '****'
在函数submit方法POST中,当表单提交时,它不起作用。我有错误:
xhr.js?b50d POST https://app/login 400(错误请求)
错误:在 XMLHttpRequest.handleLoad (xhr.js?b50d) 处的 createError (createError.js?2d83) 处,请求失败,状态码为 400 (settle.js?467f)
在选项卡Network中response我有:
{"error":"invalid_client","error_description":"在标题或正文中找不到客户端凭据"}
登录
class Login extends Component {
constructor (props) {
super(props);
this.state = {
email: '',
password: ''
}
}
handle = (e) => {
const name = e.target.name;
const value = e.target.value;
this.setState({
[name]: value
});
}
submit = (event) => {
event.preventDefault();
const body1 = {
username: this.state.email,
password: this.state.password,
grant_type: 'password',
client_secret: '****',
client_id: '****'
}
axios({
method: 'post',
url: 'https://app/login',
body: body1,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(res => {
if (res.status === 200) {
console.log(res)
}
}).catch(err => {
console.error(err);
});
}
render () {
return (
<form action="" method="post" onSubmit={this.submit}>
<div>
<label htmlFor="email">Email</label>
<input type="email" required name="email"
value={this.state.email}
onChange={this.handle} />
</div>
<div>
<label htmlFor="password">Password</label>
<input type="password"name="password"
value={this.state.password}
onChange={this.handle} />
</div>
<button type="submit" value="Submit">Log</button>
</form>
)
}
}
在 POSTMAN 中发送和在应用程序中发送有什么区别?正文内容转换为字符串?
慕侠2389804
慕姐8265434
泛舟湖上清波郎朗
相关分类