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

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

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 :

  1. ` @GET("services/getProductDetails?id={id}")
  2. fun getProductDescription(@Path("id") id : Int) : Call<SearchResponce?>?`
  1. private fun setUpDescription(id : Int){
  2. val retrofit = ServerConnection.getConnection()
  3. if(retrofit!= null){
  4. apiEndPoint = retrofit.create(ApiEndPoint::class.java)
  5. }
  6. apiEndPoint.getProductDescription(id)!!.enqueue(object : Callback<SearchResponce?> {
  7. override fun onResponse(
  8. call: Call<SearchResponce?>,
  9. response: Response<SearchResponce?>
  10. ) {
  11. if (response.isSuccessful) {
  12. val product = response.body()?.product
  13. product?.let {
  14. if (product.id == id){
  15. binding.productDescription.text = HtmlCompat.fromHtml(product.description, HtmlCompat.FROM_HTML_MODE_LEGACY)
  16. }else {
  17. Toast.makeText(this@ProductDetailsActivity, "Faild Data ", Toast.LENGTH_LONG).show()
  18. }
  19. }
  20. } else {
  21. Toast.makeText(this@ProductDetailsActivity, "Faild to get Category Data ", Toast.LENGTH_LONG).show()
  22. }
  23. }
  24. override fun onFailure(call: Call<SearchResponce?>, t: Throwable) {
  25. Toast.makeText(this@ProductDetailsActivity, "Faild to get Category Data ", Toast.LENGTH_LONG).show()
  26. }
  27. })
  28. }

I am trying to get id bases product description

答案1

得分: 1

你需要使用Query代替Path

  1. @GET("services/getProductDetails")
  2. fun getProductDescription(
  3. @Query("id") id : Int
  4. ) : Call<SearchResponce?>?

这将得到以下端点:

  1. services/getProductDetails?id={id}
英文:

You need to use Query instead of Path:

  1. @GET(&quot;services/getProductDetails&quot;)
  2. fun getProductDescription(
  3. @Query(&quot;id&quot;) id : Int
  4. ) : Call&lt;SearchResponce?&gt;?

This results in the following endpoint:

  1. 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:

确定