获取传递给 Retrofit 的查询参数,在回调的 onResponse 方法内部。

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

Get the query parameter passed to retrofit inside onResponse method inside callback

问题

我有一个需求,需要在 onResponse 内部使用传递到 Retrofit 查询中的查询参数(query parameter),但仅在请求成功时使用。我不能使用全局变量,因为在收到响应之前全局变量可能会改变。

英文:

I have a requirement to use the query parameter that is passed inside retrofit query inside onResponse if it is successful. I can't use global variable as it will change before getting the response.

答案1

得分: 2

onResponse方法会提供与响应相关的原始调用:

call!!.request()

这个请求包含了与特定响应相关的URL、头部信息,以及如果存在的话,消息体。

如果解析这些数据,你可以获取到原始的参数。

英文:

The onResponse method gives you the original call related to that response:

call!!.request()

the request contains the url related to that particular response, the headers and, if present, the body.

If you parse those data you can get the original parameters

答案2

得分: 1

call.request()。url()。queryParameter("id")这解决了问题。

英文:

call.request().url().queryParameter("id") this solved the problem

huangapple
  • 本文由 发表于 2020年9月4日 22:14:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63742870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定