Retrofit2 在使用 Multipart 上传文件时抛出 ConnectionShutdownException 错误

Retrofit2 throws ConnectionShutdownException error while uploading a file using Multipart

我正在为 http 请求使用 Retrofit2 库。它工作完美,除非我尝试使用 Multipart 上传图像。我从 Gallery 中选取图像并成功设置图像视图的 imageUri。然后我从图像选择器中获取图像 uri 来声明一个文件并上传(根据 Youtube 上的一些教程)。

这是我的 Retrofit 界面

@Multipart
@POST("fm/upload.php")
Call<ResponseBody> callServerUrlSubmitNewOrderWithFiles(
        @Part MultipartBody.Part photo);

这是我的 http 调用函数 (imageUri) 是从图像选择器获取的图像 uri:

File originalFile = new File(image1Uri.getPath());

RequestBody filePart = RequestBody.create(

       MediaType.parse(getContentResolver().getType(image1Uri)),
       originalFile
    );

 //wrapping the file
 MultipartBody.Part file = 
   MultipartBody.Part.createFormData("photo", 
   originalFile.getName(), 
   filePart);


    //create retro instance
    Retrofit.Builder builder = new Retrofit.Builder()
            .baseUrl("https://mywebsite.net/")
            .addConverterFactory(GsonConverterFactory.create());

    Retrofit retrofit = builder.build();

    //get client & call object for the request
    RetroFit2Calls client = retrofit.create(RetroFit2Calls.class);

    //finally, execute the request
    Call<ResponseBody> call = 
 client.callServerUrlSubmitNewOrderWithFiles(file);

 call.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, 
    Response<ResponseBody> response) {
            Log.e(TAG, "onResponse: Uploaded"+ response.message() 
    );

        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) 
   {
            Log.e(TAG, "onFailure: ",t );

        }
    });

我收到以下错误 (onFailure):

E/SubmitRequest: onFailure: 
okhttp3.internal.http2.ConnectionShutdownException
    at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:248)
    at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:231)
    at okhttp3.internal.http2.Http2Codec.writeRequestHeaders(Http2Codec.java:117)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:50)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 

...

这是清单权限:

   <uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

在这里找到了解决方案:

我缺少一个权限请求。