【发布时间】:2021-03-22 17:06:08
【问题描述】:
下面的改造声明不起作用我已经在 build.gradel 中实现了适当的模块。这几天代码运行良好,突然停止运行,也没有出现任何错误。
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(MyImageInterface.IMAGEURL)
.addConverterFactory(ScalarsConverterFactory.create())
.build();
public interface MyImageInterface {``
String IMAGEURL = connect.cons+"book_insert.php";
@FormUrlEncoded
@POST("book_insert.php")
Call<String> getImageData(
@Field("name") String name,
@Field("image") String image
);
}
I have applied following solution for retrofit connection as suggested
public class ApiClient {
private static Retrofit retrofit = null;
static final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(40, TimeUnit.SECONDS)
.writeTimeout(50, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.build();
public static Retrofit getApiClient(){
try {
if (retrofit == null) {
Gson gson = new GsonBuilder()
.setLenient()
.create();
retrofit = new Retrofit.Builder()
.baseUrl(MyImageInterface.IMAGEURL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient)
.build();
}
}catch(Exception e)
{
Log.v("retroerror",e.getMessage());
}
return retrofit;
}
}
但是给我
错误
"baseUrl 必须以 / 结尾:
http://13387c25fbd0.ngrok.io/my1/book_insert.php"
【问题讨论】:
-
发布你使用 Retrofit 调用的代码
标签: php android image upload retrofit