简体   繁体   English

使用内容类型为 application/x-www-form-urlencoded 的 POST Fetch 调用时,从服务器返回的本机 422 不可处理实体错误

[英]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))
    }
}

Screenshot of code代码截图

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在+呼叫后内容类型中转义+作为application / x-www-form-urlencoded - How to escape + in post call content type as application/x-www-form-urlencoded 如果请求实体的内容类型不是application / x-www-form-urlencoded,则使用@FormParam。 - The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded] 如何在节点js中使用参数为application / x-www-form-urlencoded类型的POST调用 - How to consume POST call where parameter is of type application/x-www-form-urlencoded in node js 使用字符串作为请求正文时,为什么 Axios 发送我的 POST 请求时使用 Content-Type application/x-www-form-urlencoded? - Why does Axios send my POST request with Content-Type application/x-www-form-urlencoded when using a string as the request body? 使用 x-www-form-urlencoded content-type 将嵌套的 object 作为 formdata 发布 - post nested object as formdata using x-www-form-urlencoded content-type “axios.defaults.headers.common['Content-Type'] = 'application/json'” 但 axios.post 仍然是“application/x-www-form-urlencoded” - "axios.defaults.headers.common['Content-Type'] = 'application/json'" but axios.post still is "application/x-www-form-urlencoded" 如何使用在Content-Type标头中同时具有“ application / x-www-form-urlencoded”和“ charset = UTF-8”的Javascript发布HTML表单 - How to post a HTML form using Javascript that has both “application/x-www-form-urlencoded” and “charset=UTF-8” in the Content-Type header ASP.NET Core提取POST FormData()应用程序/ x-www-form-urlencoded - ASP.NET Core Fetch POST FormData() application/x-www-form-urlencoded application/x-www-form-urlencoded 和 multipart/form-data 是客户端向服务器发送数据时唯一处理的两种特殊内容类型吗? - Are application/x-www-form-urlencoded and multipart/form-data the only 2 special content types treated by the client when sending data to server? 如何使用应用程序 / x-www-form-urlencoded 发送 axios 帖子? - How to send axios post with application / x-www-form-urlencoded?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM