【发布时间】:2019-06-08 13:30:10
【问题描述】:
我正在使用 POST 请求调用简单的登录 API,以下是参数: 标题: 内容类型:application/x-www-form-urlencoded 正文: 电子邮件:字符串 密码 服务器返回的错误是:422 Unprocessable Entity
代码:
var formBody = new FormData();
formBody.set("email", "test5@gmail.com");
formBody.set("password", "12345678");
const data = new URLSearchParams(new FormData(details));
return dispatch => {
dispatch(requestData());
try {
fetch(`${BASE_URL}users/sign_in`, {
method: 'POST',
// headers: Interceptor.getHeaders(),
headers: {
Accept:'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
// body: formBody
body: data
})
.then(res => res.json())
.then(result=>
{
if (result.success === false) {}
}
)
} catch (error) {
console.log('error',error)
dispatch(failureData(error))
}
}
【问题讨论】:
-
您应该将图像中的代码添加到问题中...
-
@MosheSlavin 完成,看看
标签: javascript react-native fetch