0
私はワンプサーバーを持っています。私はアンドロイドクライアントを書いた。私はそのアプリケーションを実行すると、エミュレータ上の応答はいいです...しかし、同じコードは、実際のデバイスでは動作しません、私は応答を取得しないでください..... .....アンドロイドの物理デバイス接続にサーバを浪費しますか?
ここにコード.. 。
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;
}
Rajesh申し訳ありませんが、ネットワーキングプロジェクトに取り組んでいます。私はクライアントサーバーアプリケーションを紹介する必要がありました。クライアントコードは次のとおりです。エミュレータ上のWAMPサーバへの接続が、必要なリストで応答する場合、サーバ。しかし、物理的なデバイスに接続されている場合、それは空を返します...私は明らかに、Rajesh? –
私はそれがwampのURLと関係があると思います...しかし、私は昨日からこれを理解しようとしています。ネット上で多くの研究が行われていましたが、無駄にしていました....: –
このデバイスはサーバと同じネットワークにありますが、ポート転送を使用するには、WiFiを使用するか、Abdullah Jibalyの答えをチェックする必要があります。サーバIP 192.168.xxはプライベートIPであり、ネットワークの外部からは見えません。あなたが携帯電話のデータネットワークを使用している場合) – Rajesh