android - 在 Android 中使用 Retrofit 获取请求的表单数据
问题描述
我从根本上误解了正在发生的事情。从我阅读和研究的内容来看,多部分和数据表单似乎用于发布请求,同时我需要在我的获取请求中添加一个令牌。
需要在 Android 中使用 Retrofit 和 Kotlin 重新创建此请求
curl --location --request GET 'localhost:5000/api/657' \
--form 'token="zjdW36WT0kkrlZHzjv3IpjysT9dA6QzK"
我的改装服务
@GET("api/{id}")
suspend fun request(@Path("id") id : Long, @Part("token") token : RequestBody) : ServerResponse
我称之为有趣的地方,令牌是一个字符串
val tok: RequestBody = token.toRequestBody("text/plain".toMediaTypeOrNull())
val response: ServerResponse
try {
response = retrofitService.request(id, tok)
}
解决方案
推荐阅读
- migration - 从 PHP7.0 迁移到 7.1 和类型声明
- php - 如何在短代码中插入 php 代码 $_SESSION?
- primefaces - PrimeFaces 组织图划分问题
- elasticsearch - 在结果中具有相同属性的对象数组上的 Elasticsearch 聚合
- selenium - 无法使用 PCA 预测将文本设置为输入字段
- javascript - 使 D3 图表具有响应性
- linux - 同步并限制同时运行的shell脚本数量
- django - 如何将 TokenAuthentication 身份验证类添加到 Django FBV
- node.js - 如何在谷歌操作和对话流中保存状态
- spring - Spring Data MongoDB 注解说明