网址更新动态网址

时间:2019-11-22 20:40:17

标签: java android url retrofit retrofit2

我正在使用Retrofit 2将图像发布到服务器上,现在我正在使用此代码初始化Retrofit 2:

    public static class NetworkClient {
    private static final String BASE_URL = "http://BASE_URL/";
    private static Retrofit retrofit;

    public static Retrofit getRetrofitClient(Context context) {
        if (retrofit == null) {
            OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .build();
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .client(okHttpClient)
                    .addConverterFactory(JacksonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }
}

public interface UploadAPIs {
    @Multipart
    @POST(".../index.php/batch/putFoto/{id}")
    Call<Void> uploadAttachment(@Part MultipartBody.Part filePart);
}

然后我用下面的代码来调用它:

 MultipartBody.Part filePart = MultipartBody.Part.createFormData("datafile", file.getName(), RequestBody.create(MediaType.parse("image/*"), file));

                Call<Void> call = uploadAPIs.uploadAttachment(filePart);
                call.enqueue(new Callback<Void>() {
                    @Override
                    public void onResponse(Call<Void> call, Response<Void> response) {

                    }

                    @Override
                    public void onFailure(Call<Void> call, Throwable t) {

                    }
                });

我不知道如何在有{id}的地方插入自定义值,有什么建议吗?

0 个答案:

没有答案