0

我有一个 wamp 服务器。我已经写了我的安卓客户端。如果我运行该应用程序,则在模拟器上的响应很好……但是相同的代码在真实设备上不起作用,我的意思是我没有得到响应……

这是代码...

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;
 }
4

1 回答 1

0

解决了伙计们......这是Rajesh提到的防火墙的问题......我应该对所有可能的参数进行彻底测试......但是嘿我正在学习:)

于 2012-04-28T12:48:02.197 回答