I am using Python-Flask API on my Android Studio Kotlin application but i am getting same response with different inputs. I think there is problem on android studio maybe catching. Here is my MainActivty and YourAsyncTask (Volley) codes. “Malzemeler” is my input and “onerilen_yemekler” are response list. I dont think there is problem on my python flask api thats why i dint share it here cause api works fine when i try it on postman.
class FetchYemeklerTask(private val context: Context, private val textView: TextView) {
fun execute(url: String, malzemeler: List<String>) {
// Volley kuyruğunu başlat
val requestQueue = Volley.newRequestQueue(context)
// Gönderilecek JSON verisini oluştur
val jsonObject = JSONObject()
jsonObject.put("malzemeler", malzemeler)
// JSON nesnesini POST isteği olarak gönder
val jsonObjectRequest = object : JsonObjectRequest(Request.Method.POST, url, jsonObject,
Response.Listener { response ->
// Yanıtı işle ve TextView'e yaz
try {
val yemeklerArray = response.getJSONArray("onerilen_yemekler")
val yemeklerList = mutableListOf<String>()
for (i in 0 until yemeklerArray.length()) {
yemeklerList.add(yemeklerArray.getString(i))
}
textView.text = yemeklerList.joinToString("n")
} catch (e: Exception) {
e.printStackTrace()
}
},
Response.ErrorListener { error ->
// Hata durumunda ekrana bir mesaj yazdır
error.printStackTrace()
textView.text = "Bir hata oluştu: ${error.message}"
}) {
override fun getHeaders(): MutableMap<String, String> {
val headers = HashMap<String, String>()
headers["Cache-Control"] = "no-cache"
return headers
}
override fun getCacheKey(): String {
// Önbelleği devre dışı bırak
return super.getCacheKey() + "-no-cache"
}
}
// Request'i kuyruğa ekle
requestQueue.add(jsonObjectRequest)
}
}
MainActivity
binding.kaydetBut1.setOnClickListener {
val fetchYemeklerTask = FetchYemeklerTask(this, binding.sonucTV)
val url = "http://192.168.1.102:5000/oneri-yemekler"
val malzemeler = listOf("çilek", "yumurta", "şeker","süt")
fetchYemeklerTask.execute(url, malzemeler)
}
I try to get different responses from api