I have recently begun building an Angular Ionic app which connects to PHP scripts on an AWS EC2 server. Everything works fine except for when I try to connect through Android once the app is built on my phone.
The response is a simple 404 response with no additional information. When I look at the log on Android Studio I see the following response:
E/Capacitor: Unable to open asset URL: [api address]
I have reduced both the HttpClient call on the frontend and the php file on the backend to their most simple forms and yet still nothing:
<?php
echo "Hello";
?>
I know that Capacitor was updated to 3 only a couple of months ago and am concerned that it is related to that. I am using PHP 7.
UPDATE
The issue was indeed cleartext but the issue was made more complicated by the fact that HttpClient was not catching the error and so I was simply getting back an unknown failed response.
In order to first see that it was cleartext I first had to change HttpClient for the Native HTTP plugin and check the logs whilst testing on my phone (HTTP will not work through the browser).
Only then did I notice that I hadn't changed the config file correctly.
As long as your PHP web server is not running on the Android device directly trying to connect to localhost / 127.0.0.1 won't work and you need to use another domain / IP your web server is available on and which the Android device can access. You can also check this by simply opening the URL in the browser of the Android device.
If that is not feasible for you you could also use port forwarding via adb to forward a port of your web server to a local port on the Android device.
If you use another domain / IP make sure your web server is not listening to local connections only and is not blocked by a firewall or similar.
Also if you are using an unencrypted connection (i.e. http instead of https) you might need to enable the cleartext config option in you Capacitor config.
Related
I'm at a complete loss as to why this is failing, so get ready for the novel describing exactly what I'm trying to accomplish and what I've tested so far.
Goal:
I'm building a webpage on my GoDaddy hosting account that I want to connect to my locally hosted Radarr server's API via PHP cURL.
I want to use PHP so I can obfuscate the IP, port, and APIKey on the client side. Plus, some of Radarr's API calls I would like to use cannot be run via query string.
Problem:
No matter what I try, I am getting nothing but the following error:
Failed to connect to <MY PUBLIC IP ADDRESS> port <PORT NUMBER>: Connection refused
(And yes, this is the publicly opened port, not the internal port on the server.)
Setup:
I installed Radarr on a FreeNAS (11.3-U5) jail hosted in my home. This is working beautifully.
I setup the FreeNAS jail with a dedicated IP address instead of allowing it to NAT internally, just to make sure it doesn't cause any issues.
I configured port forwarding on my router to allow external traffic into the Radarr server. This is working. Note: Xfinity is my ISP, but I purchased the router separately.
I have a GoDaddy hosting account where I've written a webpage to tie into Radarr's API on my local network. Currently, the webpage is also working beautifully to query data from the API, BUT it's connecting to Radarr via $.getJSON with JavaScript and jQuery.
(Before anyone says it, yes, I know GoDaddy hosting isn't the best option, but it's the one I'm using.)
Testing:
I swear I've tested EVERYTHING and I don't know why this is failing.
This IS working through the JavaScript/jQuery solution, meaning the Radarr server is up and running, the port is properly forwarded through my router, and GoDaddy's hosting isn't blocking the connection.
I CAN access the raw JSON API response in the browser simply by entering the full API URL call.
And while I'd say I am versed in PHP, I'm certainly no expert, so I even tried pulling a generic PHP cURL script from another StackOverflow post, changing the URL to mine, and running that with no luck. Note: The original script DID work to connect to another external API though.
Then I tried Postman, which worked, and I used Postman to create a PHP script, but that script failed.
All of the functional testing done on my local network was done using my publicly facing IP address. However, just to be certain, I also tried reaching the API through the browser off my network, and that worked just fine.
In a desperate attempt, I also reached out to GoDaddy support to see if they had any ideas. They went as far as creating a test PHP cURL script in the same hosting directory and had it simply pull Google's homepage. That worked just fine.
After GoDaddy was unable to help, I setup a free hosting account and free subdomain on AwardSpace, uploaded the script, and that failed too.
In digging into the Connection Refused error, someone suggested just trying to ping the IP through PHP. I attempted this, but it returned 100% packet loss. Also, I logged into my router and watched the incoming connections as I tested. Using the jQuery solution, I saw the incoming connection and it worked great. Using the PHP solution, it didn't register anything inbound.
Lastly, I have confirmed that the publicly opened port on my router is in the list of blocked port by Xfinity. However, since I can access the server externally through the browser and via the jQuery script, that can't be the issue.
There seem to be many, many, many articles online about the general Connection Refused error, but I haven't found a solution to my problem from any of them.
Does anyone have any suggestions?
I had built a website as a dashboard (using 000webhost) to change the data in mySQL database via php which was working fine right now. After that, I have a Unity WebGL build uploaded on itch.io which was working fine as well until it need to get data from the database via php. When I was intended to get the data via accessing php files store in the 000webhost server, I got the following error show up in the web console from the accessing website.
Mixed Content: The page at 'https://.itch.io/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://:54998/'. This request has been blocked; this endpoint must be available over WSS
The link I was using to access the php files was using https instead of http. I am still new to these area, I would like to know can I change the WebSocket endpoint to wss instead of ws? Do I need a paid plan to solve this? I did saw that the Single Hosting plan did offer free SSL certificate. Please help me, I am open for any suggestion/advice, Thank You.
The Websocket Server itself need to setup the SSL Certificate. If it doesnt, you need a reverse proxy like nginx or apache to handle the SSL and forwarding to the unencrypted ws:// websocket.
Anyway, the websocket should run on default port 443/80 as well, since many firewalls are blocking non default ports for security reasons. In this case you will need the reverseproxy if you dont have a dedicated IP for the websocket server.
Use socket.io. Most of the problems are solved and there is no need to do more.
var socket = io.connect('https://www...', {secure: true});
I want to monitor all HTTP requests going to the internet from a locally deployed Wordpress instance (on XAMPP server) on Fiddler. I guess I may need to configure XAMPP (or php specifically) to route all the requests going from it to the internet via Fiddler proxy but I am not sure how to do that. Has someone done this before?
Flow:
1. Wordpress (on a local XAMPP instance) makes an ajax call to the internet via a plugin.
2. I want to check the HTTP request and response for debugging.
3. I configured Fiddler to monitor localhost traffic but that does not show me requests sent by XAMPP.
4. Stuck!
I have a web application which gets data from itself via a REST API in JSON format. I am in the process of moving this site to a new server on a new host. I have everything moved, same database, same files. The main differences would be that PHP is running as a module on the new server instead of FastCGI and the new host has a client-configurable-firewall.
The web app makes the API call by using Pear's HTTP_Request object (GET method). When I run the web app that makes the call, it spins until it finally returns a "Connection timed out" error.
However, if I echo the URL being used by the call and then hit that directly in my browser it returns all the JSON data instantly.
I am wondering if this could be a firewall issue: port or protocol used by the guts of Pear's HTTP_Request object blocked? (There is currently a firewall policy allowing traffic on port 80 from any IP).
Or a permission issue: PHP running as a module is more sensitive to this.
Any ideas would be greatly appreciated!
As the new server is still only being tested using the IP address, the internal web application was attempting to access itself via an external IP. From the server itself, the external IP is not available. It has to be changed to point to the internal network IP for testing.
Once the domain name is moved this will become a non-issue again.
I have developed an android app that connect mysql database using php. when making https request to scripts php from other computers located on the same local network no problem, but when trying to request the same scripts from my android phone it gives tcp errors.
There is however a far better solution. You can access your host machine with the IP address "10.0.2.2".
This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via http://10.0.2.2:8080.
What error do you get? If it's a forbidden error then it could be your httpd config file blocking your android. Can you tell from the error whether the problem is in your android application or a network connectivity error?