Closed zibit1985 closed 1 year ago
in the emulator, what is less than 2 kb is sent from the phone does not go away (size 30-50 kb) writes I/System.out: java.io.IOException: unexpected end of stream on http:// what can not be tell me?
I/System.out: java.io.IOException: unexpected end of stream on http://
`public Boolean SendImage_ms(String serverURL) { try {
Bitmap image = photo_img_ms; String id_ms = ID_Item.toString(); String filename = "image.png"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 10, baos); // String encoded_file; // encoded_file = Base64.getEncoder().encodeToString(baos.toByteArray()); RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) .addFormDataPart("file", filename, RequestBody.create(MEDIA_TYPE_PNG, baos.toByteArray())) .addFormDataPart("id", id_ms) //.addFormDataPart("file", encoded_file) .addFormDataPart("api_key", api_key) .build(); Request request = new Request.Builder() .url(serverURL) .addHeader("Content-Type", "multipart/form-data; boundary=something") .addHeader("Connection", "close") .method("POST",body) .build(); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(new LoggingInterceptor()) .writeTimeout(600, TimeUnit.SECONDS) .readTimeout(600, TimeUnit.SECONDS) .retryOnConnectionFailure(true) .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(@NonNull Call call, @NonNull IOException e) { System.out.println(e.toString()); } @Override public void onResponse(final Call call, final Response response) throws IOException { if (!response.isSuccessful()) { System.out.println("error"); } System.out.println(response.body().string()); } }); return true; } catch (Exception ex) { System.out.println(ex.toString()); // Handle the error } return false; } class LoggingInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); long t1 = System.nanoTime(); Log.d("OkHttp", String.format("Sending request %s on %s%n%s", request.url(), chain.connection(), request.headers(), request.body(),request.toString())); Response response = chain.proceed(request); long t2 = System.nanoTime(); Log.d("OkHttp", String.format("Received response for %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers())); return response; } }`
We can't provide 1:1 user support. Sorry.
I'd suggest using a site like stackoverflow, or make a reproducible bug report, such as a standalone test that fails.
Try without LoggingInterceptor ref #8138
LoggingInterceptor
in the emulator, what is less than 2 kb is sent from the phone does not go away (size 30-50 kb) writes
I/System.out: java.io.IOException: unexpected end of stream on http://
what can not be tell me?