【发布时间】:2022-04-08 20:54:57
【问题描述】:
我正在调用带有一些参数的发布 API。一个参数是
activatecode="aaaaaa$rr"
当 API 调用时,它被发送为
activatecode=aaaaaa%24rr
$ 被编码为 %24。如何避免这种情况并按原样发送特殊字符?
【问题讨论】:
-
一个类似的问题没有答案。 stackoverflow.com/questions/45925251/…
我正在调用带有一些参数的发布 API。一个参数是
activatecode="aaaaaa$rr"
当 API 调用时,它被发送为
activatecode=aaaaaa%24rr
$ 被编码为 %24。如何避免这种情况并按原样发送特殊字符?
【问题讨论】:
我正在使用 Retrofit 2.9.0。
我有这项服务:
interface WordpressService {
@GET("wp-json/wp/v2/posts")
suspend fun getPosts(
@Query("page") page: Int,
@Query("per_page") limit: Int,
@Query("_fields", encoded = true) fields: String = "date,link,title,content,excerpt,author"
): List<Post>
}
没有输入encode = true,我最终得到了这个请求:
GET http://example.org/wp-json/wp/v2/posts?page=1&per_page=10&_fields=date%2Clink%2Ctitle%2Ccontent%2Cexcerpt%2Cauthor
使用encode = true,我得到:
GET http://motspirituel.org/wp-json/wp/v2/posts?page=1&per_page=10&_fields=date,link,title,content,excerpt,author
所以就我而言,在注释中添加encode = true 解决了我的问题。
【讨论】: