I am trying to call my backend using Retrofit client from Android Studio and my backend is ASP.NET Core 3.1, the route specified is [Route("api/getProducts")]. Retrofit client seems to call my route just fine, but after string searchStr is received, the searchStr is null. I am not sure why this is happening.
When I use postman to test, it works just fine.
It doesnt seem to matter what string value I send with retrofit client, it is always null.
Here is my retrofit function:
private fun findProducts(inputStr: String) { val paramObject = JSONObject() paramObject.put("searchStr", inputStr) val call = myApi.findProducts(paramObject.toString()) call.enqueue(object : Callback<ProductRes> { override fun onResponse(call: Call<ProductRes>, response: Response<ProductRes>) { Log.e(TAG, "message onResponse: " + response.body()!!.message.toString()) Log.e(TAG, "findProducts onResponse: " + response.body()!!.productList.asList()) } override fun onFailure(call: Call<ProductRes>, t: Throwable) { Log.e(TAG, "findProducts onFailure: " + t.localizedMessage) } }) } Here is my IMyAPI.kt code:
@Headers("Content-Type: application/json") @POST("api/getProducts") fun findProducts(@Body searchStr: String?):Call<ProductRes> https://stackoverflow.com/questions/66937428/asp-net-core-is-receiving-string-input-as-null-from-android-retrofit-client April 04, 2021 at 10:04AM


没有评论:
发表评论