Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When I call a Web Service, it returns me this exception: java.net.SocketException Permission denied. I dont know waht is the actual problem. I don't 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 below code in the manifest.

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

But I got another exception : java.net.ConnectException: localhost/127.0.0.1:80 - Connection Refused.

Please tell me how to avoid this problem.

share|improve this question
 
Have you include the web permission in your manifest ? –  xandy Nov 23 '10 at 6:07
 
thank you so much xandy... Your suggestion removes the SocketException. But I got another exception : java.net.ConnectException: localhost/127.0.0.1:80 - Connection Refused. Please tell me how to avoid this also... –  Miya Nov 23 '10 at 6:59
 
Thanks had the same problem and your solution worked. –  Anshuman Jasrotia Sep 24 '12 at 7:26
add comment

4 Answers

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

ifconfig

get the real network address instead of loopback and use that real network adress.

share|improve this answer
 
The URL does not exist any more. –  BurninLeo Jun 24 '12 at 20:34
 
PS: Here's a new one: droidnova.com/… (in short: Use the IP 10.0.2.2) –  BurninLeo Jun 24 '12 at 20:53
add comment

Are you actually running a webserver on localhost?

If so, have you verified it's listening with netstat and actually tested it with a known-working client such as the browser or netcat (nc)?

And do you realize that localhost means the android device itself? If the server is running on a development machine hosting an emulator, you need to use the special alias address for the development machine loopback instead. If your app is running on an actual phone, it's even more complicated to contact a server on your pc, unless you go via wifi or set up USB tethering.

share|improve this answer
 
thank you for this suggestion.. –  Miya Nov 23 '10 at 12:27
add comment

I just change to my ethernet IP Address 192.168.1.80 instead of using "localhost" or "127.0.0.1", and it works ...

share|improve this answer
add comment

i got that solution. i changed the configuration file of Apache Server. (I have celled a web service that is in php)

share|improve this answer
add comment

protected by Community Jun 10 '11 at 13:14

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.