【发布时间】:2021-07-07 20:52:14
【问题描述】:
无法通过 android 连接到本地服务器。服务器工作正常(通过控制台检查+通过电话控制台检查)。 在服务器上,端口指定为 3000 本地服务器设备 ID 192.168.0.107
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ApiInterface.create()
}
}
interface ApiInterface {
@GET("volley_array.json")
fun getMovies() : List<String>
companion object {
private const val BASE_URL = "https://192.168.0.107:3000"
fun create() : ApiInterface {
val retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build()
return retrofit.create(ApiInterface::class.java)
}
}
}
【问题讨论】:
-
将 / 添加到基本 url 的末尾。
标签: java android kotlin retrofit