I am building an android application for one of my university courses. I have a localhost server running on my laptop using xampp. The android application running on my phone has to connect to the localhost to get data from a MySQL database (through a php script). I use HTTPClient in my code to connect to the server. The code works fine, but because my ip address changes I need to keep changing the url in HTTPpost. My question is how can I get a static ip address? I need this to work anywhere I am, for example I will be coding and testing at home, but I will eventually have to show a working application at university. Here is my HTTP code:
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());
}