改造2 RequestBody writeTo()方法调用两次

改造2 RequestBody writeTo()方法调用两次,我使用的代码如下:

ProgressRequestBody requestVideoFile = new ProgressRequestBody(videoFile, new ProgressRequestBody.UploadCallbacks() { VideoUploadStore store = new VideoUploadStore(); @Override public void onProgressUpdate(int percentage) { if (!mIsCancelled) { Log.i("UploadServiceManager", "Read Percentage : " + percentage); data.setUploadPercentage(percentage); store.updateUploadData(data); } } @Override public void onError() { if(!mIsCancelled) { data.setUploadPercentage(0); store.updateUploadData(data); } } @Override public void onFinish() { } }); MultipartBody.Part multipartVideo = MultipartBody.Part.createFormData("File", videoFile.getName(), requestVideoFile); 

Solutions Collecting From Web of "改造2 RequestBody writeTo()方法调用两次"

下面的解决scheme可能会帮助你,尽pipe可能为时已晚。 :p

在Api客户端中删除HttpLoggingInterceptor对象,它不会执行两次writeTo()函数。基本上, HttpLoggingInterceptor通过调用writeTo()首先加载数据缓冲区(用于内部日志用途),然后再调用writeTo()将数据上传到服务器。

  HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); httpClient.addInterceptor(logging); 

从BODY减less日志级别到HEADERS,BASIC或NONE为我解决了这个问题