Home > Back-end >  How can I use my php webapp to interact with an API on localhost?
How can I use my php webapp to interact with an API on localhost?

Time:09-25

I've written a webapp in php, which works as a standalone app, but needs to get/post new data from time to time to an API (written by a different company, for desktop software) on localhost. When connecting, it would be from a webpage/browser open on that machine.

So far I've attempted to send curl requests, basically using the generated postman curl code, and it's returning false. I'm thinking it's because it can't connect to the localhost server, possibly because it's blocked from the internet.

I've been researching for a few days, but want a solution that doesn't involve me creating security vulnerabilities in the computers I am trying to connect to, by opening them directly to the internet, and if there is a way to send requests to localhost without installing more software on them I would be partial to that kind of setup.

Does this make sense? I hope someone has some experience or wisdom in this area that could at least nudge me in the right direction.

CodePudding user response:

The localhost is always the computer where you refer to that host. You can't connect to the localhost from your webapp, because the localhost hostname for that app is the computer which runs it. You have to open a tunnel from you computer to the internet where you webapp can communicate with it. You can use ngrok to do that, for example

  • Related