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.
Related
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.
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!)
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.
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
I'm writing a Lovefilm client for Android, and it's not going too badly except I keep having problems with the remote calls to retrieve data from the API.
Does anyone have any tips for debugging remote calls like this? Can I tcpdump on Android or is there a native way of doing it?
For example, I'm using the Scribe-java library for OAuth to access the Lovefilm API, I can authenticate find and retrieve a list of films on the users account fine when the device is running Gingerbread, but trying to retrieve the accessToken on Froyo causes a blank response & and apparent response code of -1, I'd like to be able to see what's going on under the cvers their.
Another example I'd like to be able to the raw http for is trying to run a search, I get and IOError that says "Received authentication challenge is null"
I've used Fiddler (http-proxy for debugging http calls) with the android emulator in these cases. Just start the proxy, and start the emulator with the correct proxy address (-http-proxy ).
Fiddler is the most useful option. On the emulator #Scythe answer will work, but on a real device you will need to set the proxy in the Apache Http Client. The following code will do that:
HttpHost proxy = new HttpHost("youripaddr", 8888);
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
If you are using https, fiddler is not so useful. In that case can enable the build in logging support in Apache Http Client. The following code does that:
Headers only:
java.util.logging.Logger apacheHeaderLog = java.util.logging.Logger.getLogger("org.apache.http.headers");
apacheHeaderLog.setLevel(java.util.logging.Level.FINEST);
Headers & Wire:
java.util.logging.Logger apacheWireLog = java.util.logging.Logger.getLogger("org.apache.http.wire");
apacheWireLog.setLevel(java.util.logging.Level.FINEST);
Note that this will have to have a java.util.logging Handler configured at finest level and the default handler is configured to log to logcat, which will filter DEBUG (finest) entries by default.
If your system can share the wi-fi connection you should be able to route packets from any device through your system and then using wireshark you can get monitor your calls or get a tcpdump.
Also , and more importantly , it would be best if you log your network calls and responses as suggested by #Matthew
Windows 7 wi-fi connection sharing : http://www.winsupersite.com/article/faqtip/windows-7-tip-of-the-week-use-wireless-hosted-networking-to-share-an-internet-connection-wirelessly.aspx
Since I always run into similar troubles and it seems a lot of people having the same issues over and over again I wrote up a quick tutorial for debugging client-server communication by using netcat and cURL.
That of course only works for the simplified case that you always 'fake' on side of the connection.
For eavesdropping you can use tools like tcpdump or Wireshark. Which will definitely be easier if you're able to run the server instance directly on your local machine.
Stetho is a great tool from FB which helps in debugging android Apps. You can have access to local data and have a check on your network using this.
http://facebook.github.io/stetho/