在 OkHttp 3.x 中,我们可以使用以下方式获取用户代理
\nimport okhttp3.internal.Version\n\nprintln(Version.userAgent())\nRun Code Online (Sandbox Code Playgroud)\n然而,这在 OkHttp 4.x 中不再起作用。
\nhttps://github.com/square/okhttp/issues/5969中提出了一个问题,并在https://github.com/square/okhttp/pull/5981中修复中修复,但我无法解决工作。
\n变更日志中指出从 4.7.0 版本开始。
\nNew: Constant string okhttp3.VERSION. This is a string like \xe2\x80\x9c4.5.0-RC1\xe2\x80\x9d, \xe2\x80\x9c4.5.0\xe2\x80\x9d, or \xe2\x80\x9c4.6.0-SNAPSHOT\xe2\x80\x9d indicating the version of OkHttp in the current runtime. Use this to include the OkHttp version in custom User-Agent headers.\nRun Code Online (Sandbox Code Playgroud)\n但我就是无法导入okhttp3.VERSION
清除缓存并重新同步后,我现在可以获得该版本
import okhttp3.OkHttp.VERSION
println(VERSION)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3194 次 |
| 最近记录: |