简体   繁体   中英

Not receiving data on server when doing an API POST call from the client

Already checked the endpoint with Insomnia and is working fine, but when trying to connect with the backend from the client there is some kind of problem. The connection between the client and the server is done this way:

const uri = `${basePath}/${baseVersion}/sign-up`;
    const params = {
        method: "POST",
        body: JSON.stringify(data),
        header: {
            "Content-Type": "application/json"
        }
    };

And if I show in the console params object this is what is inside it:

enter image description here

Just to clarify, there isn't a CORS problem as I am using a Google Chrome extension for it.

This is the response of the fecth:

enter image description here

Is your problem not receiving a response from the server in the promise? If so, that is because there is no code in your snippet that actually returns the data. (Sorry if I misidentified the problem, I don't have the ability to comment)

const uri = `${basePath}/${baseVersion}/sign-up`;
 async function fetchPost(data = {}) {
   var response = await fetch(uri,
        method: "POST",
        mode: "cors",
        header: {
            "Content-Type": "application/json"
       },
       referrerPolicy: "strict-origin-when-cross-origin" //you can replace that with anything you want depending on the situation
       body: JSON.stringify(data)
    });
    // if you're expecting the response to be json, use the below, but if you want it in text, then do response.text, etc.
    return response.json(); 
    }
    fetchPost();

   
      

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM