【问题标题】:React native 422 Unprocessable Entity error returned from server when using POST Fetch call with content type: application/x-www-form-urlencoded使用内容类型为:application/x-www-form-urlencoded 的 POST Fetch 调用时,从服务器返回本机 422 Unprocessable Entity 错误
【发布时间】: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))
    }
}

Screenshot of code

【问题讨论】:

  • 您应该将图像中的代码添加到问题中...
  • @MosheSlavin 完成,看看

标签: javascript react-native fetch


【解决方案1】:

得到了答案,422 基本上是由语义问题引起的,在我的情况下,我的请求标头的来源为空。

【讨论】:

  • 请求头的来源是什么意思?
猜你喜欢
  • 1970-01-01
  • 2020-04-21
  • 2015-04-02
  • 1970-01-01
  • 2017-08-26
  • 1970-01-01
  • 1970-01-01
  • 2021-02-03
相关资源
最近更新 更多