As someone new to Web requests, I have encountered a challenge that seems simple but has proven difficult for me. Despite searching the web, I am struggling to get a working response.
When I input the URL 'http://www.test.com/callservice.php?action=stop&x=1&y=2&ct=100' into my browser, I receive a JSON response from a particular site.
Now, I am attempting to achieve the same outcome using Axios in Javascript.
My initial attempts involve direct use of the URL:
componentWillMount() {
axios.get('http://www.test.com/callservice.php?action=stop&x=1&y=2&ct=100')
.then(response => console.log(response));
}
Alternatively, I have tried incorporating GET params:
componentWillMount() {
axios.get('http://www.test.com/callservice.php', {
params: {
action: 'stop',
x: 1,
y: 2,
ct: 100
}
})
.then(response => console.log(response));
}
Unfortunately, both avenues result in the same error message:
Possible Unhandled Promise Rejection (id: 0):
Network Error
Error: Network Error
A more detailed error explanation is provided upon further investigation:
Error: Network Error
at createError (createError.js:15)
at XMLHttpRequest.handleError (xhr.js:87)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:542)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:378)
at XMLHttpRequest.js:482
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:236)
at MessageQueue.js:108
at guard (MessageQueue.js:46)