Wamp服务器到android物理设备连接?

时间:2012-04-26 04:54:20

标签: android wamp

我有一个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;
 }

1 个答案:

答案 0 :(得分:0)

解决了它们......正如Rajesh所提到的那样是防火墙的问题......我应该对所有可能的参数进行全面测试......但是嘿,我正在学习:)