-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Closed
Description
Okhttp multipart/form-data always failing on java.net.ProtocolException: expected x bytes but received y bytes, and the amount is always an extra of 67 bytes. Tested the code for multipart/form-data on HTC, Nexus, Motorola, Samsung s7 and two Samsung S6. The multipart post works on all the other phone but the two S6. The Samsung S6, S7 and HTC were all running on the same OS version which is Android 6 Marshmallow. Here is the code I was using:
` public void HTTPPostImage(File imageFile, String imageName, Context context)
throws IOException {
// Build the RequestBody with the event id and the photo.
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("name", imageName)
.addFormDataPart("action", "upload")
.addFormDataPart("filename", imageName)
.addFormDataPart("image", imageName,
RequestBody.create(MEDIA_TYPE_JPEG, imageFile))
.build();
Request request = new Request.Builder().url(POST_NEW_IMAGE_URL).post(requestBody).build();
try (Response response = mHttpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException(TAG + "The response is " + response.body());
}
}
}`
Also, the issue exist in both okhttp2 and okhttp3.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels