[英]React native 422 Unprocessable Entity error returned from server when using POST Fetch call with content type: application/x-www-form-urlencoded
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我打电话与POST请求下面一个简单的登录API是在PARAMS:头:内容类型:应用程序/ x-WWW窗体-urlencoded身体:电子邮件:字符串密码错误时从服务器返回的是:422无法处理的实体
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 基本上是由语义问题引起的,就我而言,我的请求标头的来源为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.