我有两个 Activity ,在第一个 Activity 中,我通过改造调用 api
private fun retrofitConfiguration() {
retrofit = Retrofit.Builder()
.baseUrl("https://abhi-debug.github.io/")
.addConverterFactory(GsonConverterFactory.create())
.build()
}
和Api接口(interface)-
interface ApiService {
@GET("Caption/caption_home.json")
fun fetchUser() : Call<List<Captions>>
@GET(" ")
fun fetchData(): Call<List<Data>>
}
所以它给了我一个像这样的 json-
[
{
"id": 14,
"title": "Demo",
"url": "https://abhi-debug.github.io/Caption/demo.json"
}
]
这里的 url-"https://abhi-debug.github.io/Caption/demo.json "将作为下一个 Activity 的 Retrofit 的 BaseUrl 在下一个 Activity 中传递。
private fun retrofitConfiguration() {
retrofit = Retrofit.Builder()
.baseUrl(**myUrl**)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
myUrl 像这样从 (FirstActivity)json 获取-
myUrl = intent.getStringExtra("URL")
在 FirstActivity 中
urlForNextActivity[pos] = captionsList[pos].url
val intent = Intent(context, **SecondActivity**::class.java)
intent.putExtra("URL", urlForNextActivity[position])
context.startActivity(intent)
运行时出错
Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: https://abhi-debug.github.io/Caption/demo.json
注意- https://abhi-debug.github.io/Caption/demo.json是固定的它不能 有/结束
那么有没有什么方法可以调用呢
最佳答案
您的 baseUrl 必须在 https://abhi-debug.github.io/ 中 这种格式。
如果您缺少最后一个 /(即正斜杠),它会给您带来错误。
关于java - 如何在baseUrl中调用没有反斜杠的改造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59084334/