Last active
June 2, 2025 17:33
-
-
Save anta40/c8a7407efee91f3416135e7547c2d70a to your computer and use it in GitHub Desktop.
Form data pakai Retrofit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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