ild like to recode my project and use okHttp instead of the default HttpClient implemented in Android.
I've downloaded the latest source of the okhttp-main release.
Now ive found some examples how to create and build a POST Request.
Now my Problem. I want to create a RequestBody which keep several Data (Strings, Files, whatever) but i can't assign them directly.
Means that the RequestBuilder must go through different Loops where it get it's data added.
OkHTTPs RequestBody seems to need the data immediatly as listed in the example https://github.com/square/okhttp/wiki/Recipes
When i want to try something like
RequestBody requestBody = new MultipartBuilder().type(MultipartBuilder.FORM);
for (Object aMData : dataClass.getData().entrySet()) {
Map.Entry mapEntry = (Map.Entry) aMData;
String keyValue = (String) mapEntry.getKey();
String value = (String) mapEntry.getValue();
requestBody.addPart(keyValue, value);
}
for (DataPackage dataPackage : dataClass.getDataPackages()) {
requestBody.addPart("upfile[]", dataPackage.getFile());
}
requestBody.build();
it fails because build() itself create the RequestBody. Before it's just a MultipartBuilder(). If i try to force the type to RequestBody it wont compile/run.
So, what is the proper way adding thos data after creating a MultiPartBuilder and add DATA and Strings?