Am trying to make web service call but this error keeps throwing in the fetch method.
I actually don't have any header to be passed. It's a plain httpGet call.
WebServiceHandler.get('https://jsonplaceholder.typicode.com/todos',null,null)
.then((val)=>{
Alert.alert(val);
console.log('callapi: ' + JSON.stringify(val))
this.setState({data:val})
})
The code is supposed to return a list of objects. Any idea where am going wrong ? thanks in advance.
Try passing empty objects, instead of null
:
WebServiceHandler.get(
'https://jsonplaceholder.typicode.com/todos',
{},
{}
).then(val => {
Alert.alert(val);
console.log('callapi: ' + JSON.stringify(val));
this.setState({ data: val });
});
try to catch the errors,
WebServiceHandler.get('https://jsonplaceholder.typicode.com/todos',null,{'completed':'true'})
.then((val)=>{
console.log('callapi: ' + JSON.stringify(val))
this.setState({data:val})
})
.catch((error) => console.log('callapi:'+ JSON.stringify(error)));
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.