【问题标题】:Add dynamic value in url retrofit在 url 改造中添加动态值
【发布时间】:2022-01-23 07:24:30
【问题描述】:

我在下面有这个网址

URL TO CALL

在我的界面中

@GET("storage/presigned-url?bucketName=files&key=payment-receipt/{fileName}&httpVerb=2&contentType=image/jpeg")
suspend fun fileUploadPathCheque(@Path("fileName") name: String): Response<String>

我想用某个值替换文件名

我将函数调用为

Api.fileUploadPathCheque(UUID.randomUUID().toString().plus(".jpg"))

我得到以下异常

ava.lang.IllegalArgumentException: URL query string "bucketName=files&key=payment-receipt/{fileName}&httpVerb=2&contentType=image/jpeg" must not have replace block. For dynamic query parameters use @Query.

正确的做法应该是什么?

【问题讨论】:

    标签: android retrofit illegalargumentexception


    【解决方案1】:

    异常是不言自明的,您需要使用key 的查询参数。类似的东西

    @GET("storage/presigned-url?bucketName=files&httpVerb=2&contentType=image/jpeg")
    suspend fun fileUploadPathCheque(@Query("key") name: String): Response<String>`
    

    然后调用它,将payment-receipt/ 附加到您的传递参数:

    Api.fileUploadPathCheque("payment-receipt/" + UUID.randomUUID().toString().plus(".jpg"))
    

    这应该适合你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 2023-03-16
      • 2016-12-09
      • 2014-11-24
      相关资源
      最近更新 更多