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;
}
Rajesh對不起,我正在從事網絡項目。我需要展示一個客戶端 - 服務器應用程序。客戶端代碼如圖所示。如果服務器連接到仿真器上的wamp服務器,則會響應我們想要的列表。但是,如果連接到物理設備,它將返回空。我清楚,Rajesh? – 2012-04-26 05:05:28
我想它與wamp網址有關......但我一直試圖從昨天得出這個數字。在網上做了很多研究,但無濟於事...... :( – 2012-04-26 05:08:34
請確保該設備與服務器在同一網絡中,您可能必須使用WiFi或查看下面的Abdullah Jibaly的答案以使用端口轉發。服務器IP 192.168.xx是一個私有IP,並且不會從網絡外部看到(例如,如果你正在使用蜂窩數據網絡) – Rajesh 2012-04-26 05:11:09