I am developing an app in Android, and the emulator is not connecting to my localhost.
I have researched the issue and found some ideas but nothing seems to be working.
Below is the code i have been using:,
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://10.0.2.2/YES_BUTTON.php");
httpclient.execute(httpPost);
I have also tried a connection using "http://10.0.2.2:3128/YES_BUTTON.php";
The code would run a php file, but nothing happens, I have also checked the server access log and no connection was ever made with the Apache server from the emulator.
This is my first time building an app, and was wondering if there was something I haven't done, do I need to map the emulator port with the 3128 port on Apache, disable the firewall? I am developing the app on a laptop,with the Apache Server on the laptop also, so everything is being done on the same machine. Is there anything I havent done that needs to be done?
I bet you forgot to add the INTERNET permission :)
INTERNET
Related
I am creating an app that is going to be used on-site only, meaning it is only using it behind layers of high security.
Issue is that due to this security, the app cannot connect to the webservice which is installed on their server. We have already confirmed that the use of a private certificate is causing the issue, we continuously get javax.net.ssl.SSLPeerUnverifiedException... the certificate cannot be shared with us so i cannot install it directly into the application.
The devices that the app will be installed on already have VPN, but yet the connection issue persists.
A suggested work around is to use a proxy and PAC file. I was given the link to the PAC file (http://proxy-testcompany.com:3000/testproxy.pac) , but how can i use this link to help enhance the connection in order to connect to their webservice?
I use SOAP with HttpTransportSE
this is what i have implemented to far, but i dont think this is going to be a proper solution... if there is a solution available at all using a proxy.
InetSocketAddress sa = InetSocketAddress.createUnresolved("http://proxy-testcompany.com:3000/testproxy.pac", 3000);
Proxy proxy = new Proxy(Proxy.Type.HTTP, sa);
androidHttpTransport = new HttpTransportSE(proxy, URL, 50000); // adding proxy
Any suggestions would be fantastic.
I have set my Google Nexus 4 device to the Français (France) setting, and am browsing a site that is localized via the Accept-Language HTTP header from the client.
However, when I look at the Accept-Language settings arriving at the server, I see is is just en-US.
If I use the Dolphin browser to view the same site on the same device, the header comes in as fr-FR,en-US;q=0.8, and the site displays correctly in French.
The Nexus 4 is a development device, running Android 4.4.2; Nexus 4 Build/KOT49H. The version of Chrome is 32.0.1700.99.
Does anyone know how I get Chrome to honor the device's Language setting?
I am developing an Android app, and was expecting that the HTTP client org.apache.http.client.HttpClient would honor setting the Accept-LanguageHTTP header when calling my web service. However it doesn't, and I'm trying to figure out why.
The Chrome browser also exhibits this behavior, so I thought I would see if anyone else has this issue (posting my code is a little convoluted, and not really appropriate).
Do I really have to explicitly set the HTTP headers based on what I get back from Locale.getDefault().getLanguage() ?
It seems that is not the intent of being able to set the user's language via the Android settings.
So are you doing the following steps? (I'd imagine from your question that you already are, but I want to check because this works for me)
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(webServiceUrl);
request.addHeader("Accept-Language", "fr");
HttpResponse response = client.execute(request);
it is my second time asking a question on stackoverflow. I'm trying to access to my local apache server that I've set up on my desktop computer (ip that starts with ie. 192.168.1*.**)on my android phone. but somehow it does not allow me to access to the server at all! :( strangely, sometimes it does allow me to access to the server lol! but it's only one out of 20 for each attempts. Also, it doesn't allow me to access to the server on my laptop either.. I really need some help guys.. it was working fine when i was working locally within my desktop pc by using emulator. I've done quite a lot of research about it but i wasn't able to find any solutions.
Thank you guys
=====================================
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
HttpClient client = new DefaultHttpClient(setHttpParams());
HttpPost request = new HttpPost(PATH + FILENAME);
if (json != null) {
request.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
request.setHeader("json", json.toString());
} else {
request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
}
HttpResponse response = client.execute(request);
so that is the code, error occurs when it tries to execute the request. request includes the apache server ip PATH (192.168.**) + FILE_NAME(ie. index.php). I know why it causes the error because i cannot access to the 192.168.* server and read the desired file. I need help with this =(
For the computer running the webserver:
Make sure that your personal firewall rules are not preventing access to the web server.
For your phone to access the webserver over the air the server needs to be accessible from the web. It could be that your machine is behind a corporate firewall which is preventing access to it from external sources.
If you simply want to access it from the phone, make sure that both the webserver and phone are on the same network i.e. they have IP addresses from the same address range. You can do that by connecting your machine to wireless AP (either via ethernet or wireless) and making sure that your phone is connected to the same wireless AP.
Moreover I just read your question again and noticed the line
it does not allow access to to the server on my laptop either
If you cannot access the webserver locally on the machine it is runnning on then there is something wrong in the way you configured your web server.
So first make sure that your web server is running and configured properly. Open a browser and go to http://localhost or http://192.168.x.x if everything is configured right you will be able to access your web pages.
Basically this is networking 101, if it is still giving you problem post some details such as what webserver, what port etc.
If you are new to networking concepts and don't know how to configure a web server say Apache just Google how to configure Apache or use something called XAMPP which is a developer friendly bundle containing Apache, MySQL, PHP, FileZilla etc. Note that XAMPP shall never be used in a production environment as its default configuration is done in a way to make it easier to install, configure and run above mentioned packages for new users.
I have a python REST API server running on my laptop. I am trying to write a rest client in Android (using Eclipse ADT etc) to contact it using Apache's client (org.apache.http.client) libraries.
The code is really simple, and basically does the following -
HttpGet httpget = new HttpGet(new URI("http://10.0.2.2:8000/user?username=tim"));
HttpResponse response = httpclient.execute(httpget);
However at execute, it exceptions out with a time out exception. I cannot hit the URL even from the browser in the emulator.
Details of the exception
org.apache.http.conn.ConnectTimeoutException: Connect to /10.0.2.2:8000 timed out
However, I tried using the cREST client on Chrome on my laptop, and I am able to query the REST server fine.
Is it possible the machine is not on your network? Ie - it is on the other side of a router, on the internet somewhere? Because addresses starting "10." are reserved as private addresses and not routable.
See http://en.wikipedia.org/wiki/Private_network for more info
I had the same issue and here's how I figured out the cause:
Quit you emulator. Start your local server. In the browser, you should be able to access "http://localhost:8000/user?username=tim" and get some response. If you get a timeout, your server is likely not running. In my case, my python server had a break-point set and it was stuck there. Once I let it run, I was able to see responses on the browser and subsequently in the emulator (using 10.0.2.2).
I have a java application trying to post to a php file on an IIS server and when I execute the post I get the java.net UnknownHostException. I have the set in the androidmanifet.xml right above the application element. Can somebody please help?
If your server is on a subnet, make sure you're including the full hostname in your HttpPost, e.g. barney.awesome.domain.com and not simply barney
I figured it out. Turns out the emulator that was started through eclipse would not connect to the internet. Had to manually start it up. Does anyone know why the emulator through eclipse does not connect to the internet?