0

私はワンプサーバーを持っています。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;
 }
4

1 に答える 1

0

みんな解決しました....ラジェッシュが言ったようにファイアウォールの問題でした...すべての可能なパラメータを徹底的にテストする必要があります....しかし、ちょっと私は学んでいます:)

于 2012-04-28T12:48:02.197 に答える