大学のコースの 1 つに Android アプリケーションを作成しています。xamppを使用して、ラップトップでローカルホストサーバーを実行しています。私の電話で実行されている Android アプリケーションは、localhost に接続して MySQL データベースからデータを取得する必要があります (php スクリプトを使用)。コードで HTTPClient を使用してサーバーに接続します。コードは正常に動作しますが、IP アドレスが変更されるため、HTTPpost の URL を変更し続ける必要があります。私の質問は、静的 IP アドレスを取得するにはどうすればよいですか? たとえば、自宅でコーディングとテストを行いますが、最終的には大学で動作するアプリケーションを表示する必要があります。ここに私のHTTPコードがあります:
private String[] url = new String[] { "http://172.24.25.204:80/comp5615/select.php" };
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url[0]);
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
try {
httpPost.setEntity(new UrlEncodedFormEntity(param));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
//read content
is = httpEntity.getContent();
result = convertStreamToString(is);
} catch (Exception e) {
Log.e("log_tag", "Error in http connection "+e.toString());
}