There's a problem for API connection. Here I want to make a POST request, but connection failed/network error.
The code:
try {
// const response = await axios.post('http://127.0.0.1:8000/api/submitqrcode', { qr_code_data: data },
// getConfig()
// );
const response = await CapacitorHttp.post({
url: 'http://127.0.0.1:8000/api/submitqrcode',
headers: {"Content-Type": "application/json"},
data: {qr_code_data: data},
})
{
"appId": "com.example.app",
"appName": "QR Code Reader",
"webDir": "build",
"plugins": {
"CapacitorHttp": {
"enabled": true
}
}
}
What I've tried:
Error: net::ERR_CONNECTION_REFUSED
Error: "ConnectException" message: "Failed to connect to /127.0.0.1:8000"
Although I've tried 2 different methods, but both are showing the same type of error, which is can't connect to API. Why and how to solve this?
Ok I have found an insight from people in discord which resulted as a solution in my case.
So you will need a web server to host your backend. Thanks to my boss's help, here are the steps:
Tadaa & you're done!
So in conclusion, you will need a web server to host your backend in android devices.