英文:
java.lang.IllegalArgumentException: URL query string "id={id}" must not have replace block. For dynamic query parameters use @Query
问题
I am trying to get id-based product description.
英文:
There is a first API where I find products but if you need this product description it is in another API so now I am trying to get this description by first API id because if both API id match then you find the description. Where I am making a mistake? help me.**
API Endpoint :
` @GET("services/getProductDetails?id={id}")
fun getProductDescription(@Path("id") id : Int) : Call<SearchResponce?>?`
private fun setUpDescription(id : Int){
val retrofit = ServerConnection.getConnection()
if(retrofit!= null){
apiEndPoint = retrofit.create(ApiEndPoint::class.java)
}
apiEndPoint.getProductDescription(id)!!.enqueue(object : Callback<SearchResponce?> {
override fun onResponse(
call: Call<SearchResponce?>,
response: Response<SearchResponce?>
) {
if (response.isSuccessful) {
val product = response.body()?.product
product?.let {
if (product.id == id){
binding.productDescription.text = HtmlCompat.fromHtml(product.description, HtmlCompat.FROM_HTML_MODE_LEGACY)
}else {
Toast.makeText(this@ProductDetailsActivity, "Faild Data ", Toast.LENGTH_LONG).show()
}
}
} else {
Toast.makeText(this@ProductDetailsActivity, "Faild to get Category Data ", Toast.LENGTH_LONG).show()
}
}
override fun onFailure(call: Call<SearchResponce?>, t: Throwable) {
Toast.makeText(this@ProductDetailsActivity, "Faild to get Category Data ", Toast.LENGTH_LONG).show()
}
})
}
I am trying to get id bases product description
答案1
得分: 1
你需要使用Query代替Path
:
@GET("services/getProductDetails")
fun getProductDescription(
@Query("id") id : Int
) : Call<SearchResponce?>?
这将得到以下端点:
services/getProductDetails?id={id}
英文:
You need to use Query instead of Path
:
@GET("services/getProductDetails")
fun getProductDescription(
@Query("id") id : Int
) : Call<SearchResponce?>?
This results in the following endpoint:
services/getProductDetails?id={id}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论