I want to use string variable in place of ip address in url call. I want to make login with ip address and port number in application. then I want to save this ip address in shared preferences and then in url call i want to use that store ip address in shared preferences
I get the ip address of shared preferences like this.
SharedPreferences pref = getActivity().getSharedPreferences("MyPref", MODE_PRIVATE);
ip= pref.getString("key_ip", null); // getting Float
Log.e("ip: ", "> " + ip);
Then i call the url using method like this.
public static String off33() {
StringBuffer stringBuffer = new StringBuffer("");
BufferedReader bufferedReader = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet();
URI uri = new URI("http://10.1.1.82:80/outlet?3=ON");
httpGet.setURI(uri);
httpGet.addHeader(BasicScheme.authenticate(
new UsernamePasswordCredentials("admin", "kirti123"),
HTTP.UTF_8, false));
HttpResponse httpResponse = httpClient.execute(httpGet);
InputStream inputStream = httpResponse.getEntity().getContent();
bufferedReader = new BufferedReader(new InputStreamReader(
inputStream));
String readLine = bufferedReader.readLine();
while (readLine != null) {
stringBuffer.append(readLine);
stringBuffer.append("\n");
readLine = bufferedReader.readLine();
}
} catch (Exception e) {
// TODO: handle exception
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
// TODO: handle exception
}
}
}
return stringBuffer.toString();
}
so, I want to use ip string in place of url in method 10.1.1.82 means i want to use like this.
URI uri = new URI("http://ip:80/outlet?3=ON");
ip is a string variable and in this variable i get 10.1.1.82
so how i cant use this?