Skip to content

Instantly share code, notes, and snippets.

@anta40
Last active June 2, 2025 17:33
Show Gist options
  • Save anta40/c8a7407efee91f3416135e7547c2d70a to your computer and use it in GitHub Desktop.
Save anta40/c8a7407efee91f3416135e7547c2d70a to your computer and use it in GitHub Desktop.
Form data pakai Retrofit
// Deklarasi end point di interface
@POST("v2/something")
Call<SomeResponse> doSomethingWithForm(@Body RequestBody request);
// Buat dulu form data
// Isi dengan field2 yang diinginkan
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
builder.addFormDataPart("field_1", "nilai1");
builder.addFormDataPart("field_2", "nilai2");
// Panggil HTTP request
ApiClient.getClient().create(ApiInterface.class).doSomethingWithForm(builder.build()).enqueue(new Callback<SomeResponse>() {
@Override
public void onResponse(Call<SomeResponse> call, Response<SomeResponse> response) {
if (response.isSuccessful()) {
} else {
}
}
@Override
public void onFailure(Call<SomeResponse> call, Throwable t) {
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment