java.lang.IllegalArgumentException: URL query string "id={id}" must not have replace block. For dynamic query parameters use @Query

huangapple go评论66阅读模式
英文:

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(&quot;services/getProductDetails&quot;)
fun getProductDescription(
    @Query(&quot;id&quot;) id : Int
) : Call&lt;SearchResponce?&gt;?

This results in the following endpoint:

services/getProductDetails?id={id}

huangapple
  • 本文由 发表于 2023年5月25日 04:21:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76327156.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定