[英]How to pass data base query in URL of get request retrofit?
我正在創建一個翻新的get請求,其中我需要傳遞數據庫查詢和Kotlin中URL中的一些空格字符(如“ $”)。 但是我遇到了錯誤。
java.lang.IllegalArgumentException:URL查詢字符串不能具有replace塊。 對於動態查詢參數,請使用@Query。
這是我在郵遞員中使用的URL,但在Retrofil中卻無法使用
https://someURL.com?customParam=true&pageSize=100&query= $ filter =(drivercell eq'1111111119')$ orderby = creationTimedesc&withTotalPages = true
這是調用改造方法的代碼
val restServiceModel = DRestServiceModel.create()
val model = restServiceModel.getTripsData("Basic bWs6SU9UMTIzNCM=", "application/json", "\$filter=(drivercell%20eq'1111111119')")
這是方法
@GET("inventory/managedObjects?customParam=true&pageSize=100&{query}\$orderby=creationTimedesc&withTotalPages=true")
fun getTripsData(@Header("Authorization") token: String, @Header("Content-Type") contentType: String, @Query("query", encoded = true) query : String): Single<TripsResponseModel>
請幫我。
問題是您試圖通過另一個查詢提供Path參數時將Path參數放在查詢的中間。 您應該重新處理您的請求。 嘗試類似:
@GET("inventory/managedObjects")
fun getTripsData(@Header("Authorization") token: String,
@Header("Content-Type") contentType: String,
@Query("customParam") customParam: Boolean?,
@Query("pageSize") pageSize: Int?,
@Query("query", encoded = true) query: String,
@Query("withTotalPages") withTotalPages: Boolean?): Single<TripsResponseModel>
並像這樣使用它:
val model = restServiceModel.getTripsData("Basic bWs6SU9UMTIzNCM=", "application/json", true, 100, "your query_goes here", true)
這種方式應該起作用。
嘗試將URL中的每個$
(美元符號)字符替換為%24
因為美元符號被視為URL中的特殊字符 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.