gpt4 book ai didi

android - Android-无法连接到其余API-错误请求

转载 作者:行者123 更新时间:2023-12-02 13:19:12 25 4
gpt4 key购买 nike

我正在尝试将我的Android应用程序与运行在PC上的API连接起来。

我正在实际的手机上测试该应用程序。
基本URL是http://localhost:5000/api/

object RequestManager {
val interceptor = HttpLoggingInterceptor()
val client = OkHttpClient.Builder().addInterceptor(interceptor).build()


init {
//TODO must be None at live
interceptor.level = HttpLoggingInterceptor.Level.BODY
}


val retrofit = Retrofit.Builder()
.baseUrl("http://localhost:5000/energy/api/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()

val service = retrofit.create(Api::class.java)

}

我尝试使用http:// :5000 / energy / api /,但收到错误的请求消息。
>   D/OkHttp: <-- 400 Bad Request

有什么帮助吗?

最佳答案

尝试使用ngrok。当您插入本地主机和端口时,它可能会解决您的问题,并且为您提供了可使用的URL。

关于android - Android-无法连接到其余API-错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60385835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com