I am trying to do a user registration in react native but i am getting an error.
I have tried this
var Data56 = {
name: name,
email: email,
babyname: babyname,
phone: nuber,
// period: date2,
baby_date: date,
};
// headers: { 'content-type': 'application/x-www-form-urlencoded' },
console.log(Data56);
axios
.post("http://10.0.2.2:8000/api/register", Data56, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
})
.then((res) => {
//if succcess redirect to another url and pass data to that url
// if (res.status == 200) {
props.navigation.navigate("Home_scrren", { data: Data56 });
// }
})
.catch((error) => {
alert(error);
});
And this is the error in screenshots below
but it is working in postman
C:Usersviveksukprsavamcomponentssignupfor.jsx:122 {"message":"Network Error","name":"AxiosError","stack":"AxiosError: Network Errorn at XMLHttpRequest.handleError (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sukprsavam&modulesOnly=false&runModule=true:103296:16)","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["xhr","http"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json"},"method":"post","url":"http://10.0.2.2/api/register","data":"{"name":"vivek kn","email":"[email protected]","phone":"7558973998","baby_date":"27/12/2022"}"},"code":"ERR_NETWORK","status":null}
3
Answers
Two Solutions
Sol1:
Sol 2: install dependency for FormData;
Please try this may solve your issue.
Have a try by sending data in string format.
Install qs library to convert json data to string query parameter data.