[Vuejs]-Failed to send post request with Capacitor (works fine from regular webpage)

0👍

Too much time wasted on this one…

It turns out that the solution was to change the development server URL to an IP based one: http://127.0.0.1:8008 (in my case).

I don’t know why Capacitor doesn’t accept DNS naming.

I was able to verify it by adding this dummy endpoint to my server:

from fastapi import FastAPI, Request
...
@app.post("/dummypath")
async def get_body(request: Request):
    return await request.json()

so now from the client:

async inviteSelectedContacts() {
  // let data = {userId: 'test id', users: this.chosenContacts}
  let data = {}
  let url = `${serverURL}/dummypath`;
  try {
    let res = await axios.post(url, data);
    if (res.status === 200){
      alert(res.status)
    }
    alert(res);
    return res.data
  }
  catch (err) {
    console.log(err);
    alert(err);
  }
}

where serverURL is http://127.0.0.1:8008

Leave a comment