2012-04-26 131 views
0

我有一个wamp服务器。我写了我的Android客户端。如果我运行该应用程序,响应模拟器上进行罚款...但相同的代码并没有真正的设备,我的意思是我不得到回应.....Wamp服务器到android物理设备连接?

这里是代码的工作.. 。

public static final String SERVER_URL = "http://192.168.1.3/AndroidListServer/server.php?command=getAnimalList"; 
private static String executeHttpRequest(String data) { 
    String result = ""; 
    try { 
    URL url = new URL(SERVER_URL); 
    URLConnection connection = url.openConnection(); 

    /* 
    * We need to make sure we specify that we want to provide input and 
    * get output from this connection. We also want to disable caching, 
    * so that we get the most up-to-date result. And, we need to 
    * specify the correct content type for our data. 
    */ 
    connection.setDoInput(true); 
    connection.setDoOutput(true); 
    connection.setUseCaches(false); 
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 

    // Send the POST data 
    DataOutputStream dataOut = new DataOutputStream(connection.getOutputStream()); 
    dataOut.writeBytes(data); 
    dataOut.flush(); 
    dataOut.close(); 

    // get the response from the server and store it in result 
    DataInputStream dataIn = new DataInputStream(connection.getInputStream()); 
    String inputLine; 
    while ((inputLine = dataIn.readLine()) != null) { 
    result += inputLine; 
    } 
    dataIn.close(); 
    } catch (IOException e) { 
    /* 
    * In case of an error, we're going to return a null String. This 
    * can be changed to a specific error message format if the client 
    * wants to do some error handling. For our simple app, we're just 
    * going to use the null to communicate a general error in 
    * retrieving the data. 
    */ 
    e.printStackTrace(); 
    result = null; 
    } 

    return result; 
} 
+0

Rajesh对不起,我正在从事网络项目。我需要展示一个客户端 - 服务器应用程序。客户端代码如图所示。如果服务器连接到仿真器上的wamp服务器,则会响应我们想要的列表。但是,如果连接到物理设备,它将返回空。我清楚,Rajesh? – 2012-04-26 05:05:28

+0

我想它与wamp网址有关......但我一直试图从昨天得出这个数字。在网上做了很多研究,但无济于事...... :( – 2012-04-26 05:08:34

+1

请确保该设备与服务器在同一网络中,您可能必须使用WiFi或查看下面的Abdullah Jibaly的答案以使用端口转发。服务器IP 192.168.xx是一个私有IP,并且不会从网络外部看到(例如,如果你正在使用蜂窝数据网络) – Rajesh 2012-04-26 05:11:09

回答

0

解决这家伙....它是与作为拉杰什提到...我应该做的所有可能参数的全面测试防火墙的问题....但嘿,我在学习: )

相关问题