Http Plugin Capacitor, some questions

You should have said: Good luck and always backup my friend :laughing:

But thanks for staying with me on this..
A beer or two are waiting here in Argentina


Same result, still seeing the response on console, but the data is not being rendered in the DOM

Logcat:

2024-07-16 18:52:11.034 14377-14407 EGL_emulation           com.definitive.app                   D  app_time_stats: avg=29563.31ms min=4.80ms max=591085.12ms count=20
2024-07-16 18:52:11.123 14377-14377 Capacitor/Plugin        com.definitive.app                   V  To native (Capacitor plugin): callbackId: 77933135, pluginId: CapacitorHttp, methodName: request
2024-07-16 18:52:11.123 14377-14377 Capacitor               com.definitive.app                   V  callback: 77933135, pluginId: CapacitorHttp, methodName: request, methodData: {"url":"https:\/\/www.XXXX.com\/dmxConnect\/api\/test\/testmobile6\/queryvalue.php","method":"GET","headers":{"access-control-allow-credentials":"true","access-control-allow-origin":"capacitor:\/\/,capacitor:\/\/localhost,http:\/\/localhost,capacitor-electron:\/\/localhost,http:\/\/localhost\/*,http:\/\/localhost:33865,https:\/\/www.XXXX.com,https:\/\/XXXX.com,http:\/\/localhost:43915","alt-svc":"h3=\":443\"; ma=2592000, h3-29=\":443\"; ma=2592000, h3-Q050=\":443\"; ma=2592000, h3-Q046=\":443\"; ma=2592000, h3-Q043=\":443\"; ma=2592000, quic=\":443\"; ma=2592000; v=\"43,46\"","cache-control":"no-store, no-cache, must-revalidate","Connection":"Keep-Alive","content-type":"application\/json; charset=utf-8","date":"Tue, 16 Jul 2024 21:42:20 GMT","expires":"Thu, 19 Nov 1981 08:52:00 GMT","Keep-Alive":"timeout=5, max=100","pragma":"no-cache","server":"LiteSpeed","vary":"Origin,Accept-Encoding","X-Android-Received-Millis":"1721166140195","X-Android-Response-Source":"NETWORK 200","X-Android-Selected-Protocol":"http\/1.1","X-Android-Sent-Millis":"1721166139987","x-generator":"DMXzone Server Connect","accept":"application\/json"},"dataType":"json"}
2024-07-16 18:52:11.484 14377-15348 TrafficStats            com.definitive.app                   D  tagSocket(193) with statsTag=0xffffffff, statsUid=-1
2024-07-16 18:52:12.114 14377-14377 Capacitor/Console       com.definitive.app                   D  File: https://XXXX.com/ - Line 670 - Msg: CapacitorHttp XMLHttpRequest 1721166731116 https://www.XXXX.com/dmxConnect/api/test/testmobile6/queryvalue.php: 996.114013671875 ms

Also tried with no server on capacitor.config.json, same

Hold on we're not out of hope yet!

 <meta http-equiv="X-Content-Security-Policy" content="img-src 'self' data:; default-src 'self' 'unsafe-inline'; https://*****.com/*/ https://www.*****.com/*/ https://*/ https://*****.com/*/ script-src 'self'; object-src 'self';">

Replacing the ***** with your domain, add to each page that contains Server Actions.

I hear you have some fine coffee there! I'm up for a cup or several...

No worries man, all in it to help each other out. By hook or by crook we'll get there!

Your Capacitor config has the true flag set for the http plugin?

},
    "CapacitorHttp": {
      "enabled": true
    }

Haha

Yes:

{
  "appId": "com.appname.app",
  "appName": "appname",
  "webDir": "www",
  "bundledWebRuntime": true,
  "plugins": {
    "CapacitorCookies": {
      "enabled": true
    },
    "CapacitorHttp": {
      "enabled": true
    }
  },
  "server": {
    "androidScheme": "https",
    "hostname": "XXXX.com"
  }
}

You can remove the sever configuration, it is known to cause issues with the http plugin. And the bundledwebRuntime as this is defunct.

So replace with...

{
  "appId": "com.appname.app",
  "appName": "appname",
  "webDir": "www",
  "plugins": {
    "CapacitorCookies": {
      "enabled": true
    },
    "CapacitorHttp": {
      "enabled": true
    }
  }
}

Build, run.

Same.
Also disabled cookies plugin.
Seeing response on console, not showing up on DOM.

Remember that all works fine when using only cookies plugin.
Just trying to figure why nothing is rendered using http

Try it now with only cookies and see if it renders your data?

With only cookies:

Is it working, how about if you add a quick Server Action to grab something from a query to display? Sorry one of my dogs decided to befriend a goat... One of the highlights of living in the countryside!

1 Like

Wait a minute..
Went to http docs to clarify, and tried to execute one example on console:

const doGet = async () => {
  try {
    const options = {
      method: 'GET', 
      url: 'https://www.XXXX.com/dmxConnect/api/test/testmobile6/queryvalue.php',
      headers: { 'Content-Type': 'application/json' }
    };
    const response = await Capacitor.Plugins.Http.request(options);
    console.log(response.status);
    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
};
doGet();


and found this

File:  - Line 13 - Msg: Error: Error: NullPointerException

That takes me to:
Ionic Capacitor Community Http Native - Not working in Android device or Emulator:

That plugin has been revamped to official capacitor core plugin: CapacitorHttp

So updated by hand to latest (6.1.0)
Don't know if this was solved: New capacitor release, dependency issue

Now, all the request are not on console.
I can see it on the network tab.

I think I broke everything

Oh man you know what I'd do... I'd start again. Keep this Project as a resource, start a new Project, and follow all of the above as know it works using Capacitor "@capacitor/core": "^5.5.1", which is the Wappler default upon creation. You could end up chasing your tail for days trying to fix this... Get the basics running then go back to the original Project and take out of it what you need and apply it to your new Project..?

Yes, I think I'll do that and come back later.

Also seeing now is setted to https:
image

Just in case, your backend domain cookies option, is localhost?

Still logged after full quit app? Like working with cookies plugin?

Thanks man :beers:, will update shortly

I leave the Domain blank Franse.

Makes sense, thanks once again

1 Like

You are truly very welcome. You give an almighty amount of help within the Community, you deserve some in return when the need arises. I spent hours and created multiple apps over the past couple of days. My old ways would not work so had to adopt a new approach. Am pretty relentless when something doesn't work, quite tenacious. I will sit for hours and hours until it works. I feel you are the same way inclined. BUT we do need to take a break and walk-away for five minutes to breathe some fresh air, take a piss, pat the dogs and cats, and be the good husband. THEN we can get back to it.

:slight_smile:

1 Like

Thanks for that, yes, totally right, I don't know exactly why I need to have http plugin working, but it feels like I need to know and understand the behavior, for future reference, or just to help someone else here.

Cheers on that. Truly good advice
Sometimes is better to take some fresh air and try again.

Another day another try.
Login form only visible on console with status 200. Loading server connect I can see value rendered on page now.

Still figuring out why the login screen is not closed after succesful server connect form.

Tried on bootstrap too.

@Cheese I've re-readed all this topic again and I have one and final question..

What happens if you set the cookies plugin to false on capacitor.config.json? Still working all as it should?

One moment will try and see what happens, bare with me for a moment.

I know the feeling very well. Nothing quite like the feeling of success after issues like these. Very rewarding. I often try to explain a eureka moment to my wife... She looks at me with a blank expression. Then returns immediately to what she was doing. I don't even get a lollipop!

e00821ea65232b543e12504000f12108

1 Like

Everything works fine @franse. I added a button and a test cookie. On click of the button the cookie is set just fine.

Hahaha my gf is like: how many times you'll say "sorry for my bad english?"

Ok thanks, still trying.

@patrick sorry for the tag but can I kindly ask if you have seen this behavior before?
Don't need to read all the entire topic, just the first one