I am trying to make a fetch request from react native, It works fine on web and returns as expected (expo web) but not on android.
I keep getting 'Network request failed' and i cant see why as its working on web. I have also tried to change the status code from a 414 to a 200 on my server so that there would be no error however this just meant no response object still but without errors.
I am calling a function that makes the request here:
async function handleSubmit() {
try {
const res = await createAccountService({name: name.value,email:email.value,password:password.value})
console.log(res);
}catch(e){
console.log(e);
// alertFunction('Couldnt create account', res.error.message)
}
and this is where my request is being made from
export const createAccountService = async({name, email, password}) => {
try {
const timestamp = Math.floor(Date.now() / 1000);
// const requestObject = {name, email, password, timestamp}
const requestObject ={
name: "afdsf",
email:"s7edsg@t.com",
password:"123423569",
timestamp: 1607548529
}
const unparsedResponse = await fetch(URL + "/account/createaccount", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestObject)
})
console.log(unparsedResponse);
const response = await unparsedResponse.json()
if(response.error){
// Error - Return this to the alert
}else{
// All good - safe this to the user state
}
return response
}catch(e){
console.log('this is being hit');
throw e
}
}
This works find on web so i wonder if im missing some plugin or import or something?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…