I'm calling a simple login API with POST request following are the params: Headers : Content-type: application/x-www-form-urlencoded Body : email: String password Error returned from server is :422 Unprocessable Entity
CODE:
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))
}
}
得到了答案,422 基本上是由语义问题引起的,就我而言,我的请求标头的来源为空。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.