Disable cache at httpsURLConnection
From
Jakub@jak74@interia.pl to
comp.mobile.android on Thu Apr 16 14:39:32 2026
From Newsgroup: comp.mobile.android
i have this code to sand values to server php post.
But how to clear real cache
try {
val url = URL(destinationUrl)
httpsURLConnection = url.openConnection(Proxy.NO_PROXY) as HttpsURLConnection
httpsURLConnection.setRequestProperty("Cache-Control", "no-cache")
httpsURLConnection.setDefaultUseCaches(false);
httpsURLConnection.setUseCaches(false)
saveDataString(context, "login", email)
httpsURLConnection.requestMethod = "POST"
httpsURLConnection.doOutput = true
httpsURLConnection.doInput = true
val outputStream = httpsURLConnection.outputStream
val bufferedWriter =
BufferedWriter(OutputStreamWriter(outputStream, "UTF-8"))
//bufferedWriter.
val postData =
(
URLEncoder.encode(
"type",
"UTF-8"
) + "=" + URLEncoder.encode(
type, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"email",
"UTF-8"
) + "=" + URLEncoder.encode(
email, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"password",
"UTF-8"
) + "=" + URLEncoder.encode(
password, "UTF-8"
)
)
Log.i("ppp", "postData ->" + postData)
bufferedWriter.write(postData)
bufferedWriter.flush()
bufferedWriter.close()
outputStream.close()
val inputStream =
httpsURLConnection.inputStream
val bufferedReader =
BufferedReader(InputStreamReader(inputStream, "UTF-8"))
var line: String?
while (bufferedReader.readLine().also {
line = it } != null) {
result += line
}
bufferedReader.close()
inputStream.close()
} catch (_: IllegalStateException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: ProtocolException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: UnsupportedEncodingException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: NullPointerException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: IOException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} finally {
httpsURLConnection.disconnect()
}
}
} else if ( params[0] == "register" ) {
if ( params.size == 8 ) {
try {
val url = URL(destinationUrl)
httpsURLConnection = url.openConnection(Proxy.NO_PROXY) as HttpsURLConnection
httpsURLConnection.setRequestProperty("Cache-Control", "no-cache")
httpsURLConnection.setDefaultUseCaches(false);
httpsURLConnection.setUseCaches(false)
/*
val type = params[0]
val nameFirst = params[1]
val nameLast = params[2]
val birthday = params[3]
val isSexWomanRadioButton = params[4]
val isSexManRadioButton = params[5]
val email =
params[6]
val password = params[7]
*/
httpsURLConnection.requestMethod = "POST"
httpsURLConnection.doOutput = true
httpsURLConnection.doInput = true
val outputStream = httpsURLConnection.outputStream
val bufferedWriter =
BufferedWriter(OutputStreamWriter(outputStream, "UTF-8"))
val postData =
(
URLEncoder.encode(
"type",
"UTF-8"
) + "=" + URLEncoder.encode(
type, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"nameFirst",
"UTF-8"
) + "=" + URLEncoder.encode(
nameFirst, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"nameLast",
"UTF-8"
) + "=" + URLEncoder.encode(
nameLast, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"birthday",
"UTF-8"
) + "=" + URLEncoder.encode(
birthday, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"isSexWomanRadioButton",
"UTF-8"
) + "=" + URLEncoder.encode(
isSexWomanRadioButton, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"isSexManRadioButton",
"UTF-8"
) + "=" + URLEncoder.encode(
isSexManRadioButton, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"email",
"UTF-8"
) + "=" + URLEncoder.encode(
email, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"password",
"UTF-8"
) + "=" + URLEncoder.encode(
password, "UTF-8"
)
)
bufferedWriter.write(postData)
bufferedWriter.flush()
bufferedWriter.close()
outputStream.close()
val inputStream =
httpsURLConnection.inputStream
val bufferedReader =
BufferedReader(InputStreamReader(inputStream, "UTF-8"))
var line: String?
while (bufferedReader.readLine().also {
line = it } != null) {
result += line
}
bufferedReader.close()
inputStream.close()
} catch (_: IllegalStateException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: ProtocolException) {
//ZZZobject.
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: UnsupportedEncodingException) {
//ZZZobject.
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: NullPointerException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: IOException) {
//ZZZobject.
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} finally {
httpsURLConnection.disconnect()
}
}
} else
if ( params[0] == "registerconfirm" ) {
if ( params.size == 3 ) {
try {
val url = URL(destinationUrl)
httpsURLConnection = url.openConnection(Proxy.NO_PROXY) as HttpsURLConnection
httpsURLConnection.setRequestProperty("Cache-Control", "no-cache")
httpsURLConnection.setDefaultUseCaches(false);
httpsURLConnection.setUseCaches(false)
/*
val
type = params[0]
val registerEmailOrPhoneValue = params[1]
val
codeEnter = params[2]
*/
httpsURLConnection.requestMethod = "POST"
httpsURLConnection.doOutput = true
httpsURLConnection.doInput = true
val outputStream = httpsURLConnection.outputStream
val bufferedWriter =
BufferedWriter(OutputStreamWriter(outputStream, "UTF-8"))
val postData =
(
URLEncoder.encode(
"type",
"UTF-8"
) + "=" + URLEncoder.encode(
type, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"registerEmailOrPhoneValue",
"UTF-8"
) + "=" + URLEncoder.encode(
registerEmailOrPhoneValue, "UTF-8"
)
+ "&"
+ URLEncoder.encode(
"codeEnter",
"UTF-8"
) + "=" + URLEncoder.encode(
codeEnter, "UTF-8"
)
)
bufferedWriter.write(postData)
bufferedWriter.flush()
bufferedWriter.close()
outputStream.close()
val inputStream = httpsURLConnection.inputStream
val bufferedReader =
BufferedReader(InputStreamReader(inputStream, "UTF-8"))
var line: String?
while (bufferedReader.readLine().also {
line = it } != null) {
result += line
}
bufferedReader.close()
inputStream.close()
} catch (_: IllegalStateException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: ProtocolException) {
//ZZZobject.
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: UnsupportedEncodingException) {
//ZZZobject.
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: NullPointerException) {
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} catch (_: IOException) {
//ZZZobject.
showToast(
context,
context.resources.getString(R.string.noconnectiontointernet)
)
} finally {
httpsURLConnection.disconnect()
}
}
--- Synchronet 3.21f-Linux NewsLink 1.2