how to access webpage hosted on tomcat server from the android mobile - android

I have designed a webpage and run that on my browser using tomcat server http://localhost:8084/neclogin/main.jsp
I also accessed it from my android emulator it works well.
http://10.0.2.2:8084/neclogin/main.jsp it works well.
But when I tried on my real device (connected to PC via hotspot)
http://192.xxx.xxx.xxx:8084/neclogin/web/main.jsp
It shows on browser that HTTTP 404 ERROR - DESCRIPTION :requested resource is unavailable
I am confused whether my android mobile is unable to connect to localhost or can't trace the path of my main.jsp
FOR MORE DETAIL
1)windows 7
2)NETBEANS IDE WITH APACHE TOMCAT SERVER 8.03
3)**Both connected via wifi hotspot on my mobile**
4)path to my main.jsp is `C:\Users\dell\Documents\NetBeansProjects\neclogin\web\main.jsp`
5)path to my tomcat server installed is `C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.3`
i have disabled my windows and antivirus firewall

First try to access http://192.xxx.xxx.xxx:8084/neclogin/web/main.jsp from your PC to see if the IP is correct.
a) If that works and you can access it, then indeed there is a problem with the external access and the problem is somewhere in your firewall settings or alike. Potentially it doesn't let traffic through 'non-standard' ports (80,433 etc)
b) If you can't access it on your PC either using then you got the IP wrong. Try running ipconfig from the command line and see if with the IP listed there it works. ipconfig will return a bunch of different IPs you need to look for the one that starts with 192 most likely labeled as IPv4 or something like that.
It's also worth checking what the 404 message looks like. If it's tomcat's 404 page then you're almost there as you can access tomcat but not using the correct path.

Related

how to access a localhost website from android device

I have an ASP.net Web API in my laptop with this address :
localhost:99949
I add this to IIS Express that I can access my web Api from another computer in same lan network , and it's going this:
Nimis:80
I can access to my web api from other PCs , but when I try to access this with my android device it show me "Web page not available" error.
I turn off all my firewalls.
what should I do to fix it ?
You need to add an inbound rule in the firewall for port 80 (or whatever port you used for your website on IIS):
Go to Control Panel, Windows Firewall
Select Inbound Rules
Add a New Rule
Select "Port" as a Rule Type
Select "TCP and put "80" (and any other ports you want to open) in "Specific local ports"
Select "Allow the connection"
Select the network location where the rule should apply
Give a name and an optional description
After that you should be able to access your site from other devices in the same network using http://computername (e.g. http://myhomepc)
However you might need to use the IP of the server machine with Android. It always seems to override its DNS entries using Google's servers. In this case try to modify DNS settings as explained here.
I had the same problem and this is my solution without changing anything in FireWall or any other settings:
Get the IP of the WebService deployed by IIS-Express (run IIS-Express): For this install the extension "Conveyor" in Visual Studio: Tutorial on Youtube
To check if it is working open browser on your mobile and type in the IP shown in Conveyor: IP of WebService --> e.g. I typed URL: "http://192.168.178.51:45455/api/ToDo" to get the correct HttpGet from my Rest-Webservice
To have it running in Android Studio I used a normal HttpURLConnection (Same URL also runs on Emulator!)

Android connectivity/network configuration

I have a WebService running in a remote VM inside my company's network.
I can see the JSON response using Chrome on my laptop by typing the url in the address bar (http://VMaddress/servicename/).
However, I cannot do this using the Android emulator. My company uses a proxy and I have already defined it in both the emulator launch window and inside the Android application itself. I can connect to Google and stuff, but I still cannot connect to the remote VM.
So my question is:
How is networking handled in the Android emulator? I know it defines a different ip for localhost, but shouldn't I be able to at least see the JSON response in the emulator browser (since I defined the proxy that would allow me to access the Internet)?
Doesn't the emulator run on my laptop's connection?
I get a 403 forbidden response using both the emulator browser and the Android application.
I also tried another WebService URL (http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo) and I get a 200 response code, so my application is correctly accessing the Internet).
thanks in advance
---EDIT---
I snooped around in my connection settings in my laptop and going into the Proxy Settings in Chrome I had an exception in the proxy for the VM where my server is.
Removing that exception gives me the same 403 forbidden error I have in my emulator.
How can I apply the same exception to the emulator?
Somehow I managed to "resolve" this.
I am not entirely sure this is the reason, but I followed these steps. The emulator must start while there is no network available.
I also have the DNS servers from my company set in the Launcher menu using the options:
-dns-server server1,server2 (got the values from ipconfig /all in a command prompt). It will not work for me without these settings.
and I configured the proxy manually in the emulator by creating a new APN following these steps.

Spring Android Connection Refused ECONNREFUSED

I am trying to make a connection from my Android to my local machine on a wifi network. My machines wifi ip address is 10.27.27.172 and I am running my node.js server on port 7890. I can use my phones chrome browser and browse to my server and access some endpoints which return json. My problem comes when I try and use spring-android rest template. I have given INTERNET permissions to my android application but I still get a ECONNREFUSED error. Is this an android port issue? Is the firewall blocking my request. If so why can I browse to the server but not use the REST client to get the information?
I found the answer on this stackoverflow. You need to make sure you retype the I guess the eclipse editor sometimes adds in invisible characters or something. Anyways it is working now.

How do you access a local port 8080 url from an android http get

I have a restful web service located on a local tomcat instance.
I'm trying to access the url via a get in my application but am getting the error: host is unresolved
I try to access this url from my android emulator browser to confirm the connection there and am unable to get to it their either. An alert comes up on the screen that says: "an sd card is required to download 125562.bin"
I am not using localhost in my url but something that looks like:
http://192.168.1.2:8080/service/0/12345
It returns straight json
Does anyone know why I can't access this in the android emulator? I can successfully hit this same address from my computer browser as well as iPhone and it brings back json.
Does android handle other ports differently than standard port 80? Is the problem this url doesn't have an extension?
The Android-Emulator has a virtual router, which cut's the Emulators network from the host-computers network.
However, this router is part of the network, too and enables you to access servers running on the local machine by using the IP 10.0.2.2.
So you would use:
http://10.0.2.2:8080/service/0/12345
You need to use 10.0.2.2 to emulate your local machine's 'localhost'.
See Emulator Networking

Android WebView full page

I am creating an aplication that involves an WebView. The thing is that I want to load the full page and not the mobile one, so I have changed the User Agent. Nevertheless there are pages that loads the mobile version.
Here are two versions of code that I have tried:
1.webview.getSettings().setUserAgentString("Mozila ");
2.
String DESKTOP_USERAGENT = webview.getSettings().getUserAgentString ();
DESKTOP_USERAGENT = DESKTOP_USERAGENT.replace("Mobile ","");
webview.getSettings().setUserAgentString(DESKTOP_USERAGENT);
This are exemples of webpages that loads the mobile version in any cases:
http://www.jurnalul.ro
http://www.androidzoom.com
1.Does anyone knows how I can trick the server and tell him I am using a desktop and not a mobile?
2.How does a website knows that I am using a mobile version?
Thank you very much,
Razvan
The problem may be that if you are using a device that your carrier is routing all your HTTP requests through a proxy, and that the proxy is changing the User-Agent. Check on the other end, with your own server, using nc -l 80 -vvv that your request is indeed sending the User-Agent that you have modified.
EDIT: Some specific troubleshooting steps
Forward a port 9090 on your router to your desktop machine or laptop.
Download netcat
Run netcat with the command "nc -l 9090 -vvv"
In your Android application's WebView, make an HTTP request with the User-Agent you are injecting to http://your.ip.address:9090
In the terminal you ran netcat, you will see the HTTP request dump in plain text. There you can check the HTTP header User-Agent to see if it has been changed by a proxy server or not.
You cannot test this stuff with Wireshark or Fiddler because it is happening in the WAN. You need to test it on the receiving end, either on a server, or on your own desktop machine.
webview.getSettings().setUserAgent(1);//for desktop 1 or mobil 0.

Categories

Resources