Web service exception (java.net.SocketException Permission denied) on Android

When I call the web service, it returns this exception to me: java.net.SocketException Allowed. I do not know that this is really a problem. I do not know how to solve this?

home.java page:

try { url = new URL("http://localhost/TraderLevels/subscriber.php"); conn = (HttpURLConnection) url.openConnection(); dis = conn.getInputStream(); } catch (Exception e) { e.printStackTrace(); } 

subscriber.php

 $username="root"; $password=""; $database="mydb"; $server="localhost"; $connection = mysql_connect($server,$username,$password); if (!$connection) { die('Not connected : ' . mysql_error()); } $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die('Can\'t use db : ' . mysql_error()); } $query="SELECT * from user"; $result = mysql_query($query); $dom = new DOMDocument('1.0','UTF-8'); $dnode = $dom->createElement('usesssrdetails'); $docNode = $dom->appendChild($dnode); $result = mysql_query($query); $rowNo=1; while ($row = @mysql_fetch_assoc($result)) { $node = $dom->createElement('user'); $categoryNode = $docNode->appendChild($node); $idNode = $dom->createElement('userid',($row['userID'])); $categoryNode->appendChild($idNode); $idNode = $dom->createElement('email',($row['email'])); $categoryNode->appendChild($idNode); $rowNo=$rowNo+1; } $kmlOutput = $dom->saveXML(); echo $kmlOutput; ?> 

Update:

I solved the above problem by adding the code below to the manifest.

 < uses-permission android:name="android.permission.INTERNET" /> 

But I got one more exception: java.net.ConnectException: localhost / 127.0.0.1: 80 - Connection refused.

Please tell me how to avoid this problem.

+4
source share
4 answers

http://developer.android.com/guide/appendix/faq/commontasks.html#localhostalias

Ifconfig

get the real network address instead of loopback and use this real network address.

+4
source

Are you really running a web server on local hosting?

If so, have you tested it while listening to netstat, and actually tested it using a well-known client such as a browser or netcat (nc)?

And you understand that localhost means the Android device itself? If the server is running on a development machine that hosts the emulator, you should instead use a special alias address for the development loop. If your application runs on a real phone, it is even more difficult to contact the server on your PC if you are not connected via Wi-Fi or have not configured USB-modding.

+2
source

I just go to my Ethernet IP address 192.168.1.80 instead of using "localhost" or "127.0.0.1" and it works ...

+1
source

I got this solution. I changed the Apache Server configuration file. (I bound the web service which is in php)

0
source

All Articles