我正在尝试使用okHTTP多部分将图像上传到服务器中。服务器不接受我的请求。我的问题是我在日志记录拦截器中看不到我的多部分,所以我无法调试。这是我使用的代码和生成的日志cat以及所需的有效负载。任何帮助表示赞赏。
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("uploaded_file", filename, RequestBody.create(MEDIA_TYPE_PNG, sourceFile))
.addFormDataPart("flowChunkNumber", "1")
.addFormDataPart("flowCurrentChunkSize", String.valueOf(sourceFile.getTotalSpace()))
.addFormDataPart("flowChunkSize", "1048576")
.addFormDataPart("flowIdentifier", "4731-images1jpeg")
.addFormDataPart("flowFilename", "images (1).jpeg")
.addFormDataPart("flowFilename", "images (1).jpeg")
.addFormDataPart("flowRelativePath", "images (1).jpeg")
.addFormDataPart("flowTotalChunks", "1")
.build();
Request request = new Request.Builder()
.addHeader("cookie", ******* )
.url(URL_UPLOAD_IMAGE)
.post(requestBody)
.build();
HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient
.Builder()
.addNetworkInterceptor(logInterceptor)
.build();
Response response = client.newCall(request).execute();
这是我在使用拦截器
时在日志中看到的内容D / OkHttp: - > POST https://www.appido.ir/api/profile/avatar http / 1.1
D / OkHttp:Content-Type:multipart / form-data; 边界= a8028055-3a30-4942-916b-af56935e8b32
D / OkHttp:内容长度:14097 D / OkHttp:cookie:************************
域= .appido.ir; expires =星期二,2016年8月23日13:31:11 GMT;路径= /D / OkHttp:主持人:www.appido.ir
D / OkHttp:连接:Keep-Alive
D / OkHttp:Accept-Encoding:gzip
D / OkHttp:User-Agent:okhttp / 3.4.1
d / OkHttp: h gTRC lumi 07-2507:47:49.163 7776-8509 / com.androidbuts.uploadimage D / OkHttp:| meas 07-25 07:47:49.163 7776-8509 / com.androidbuts.uploadimage D / OkHttp: $bkpt 07-2507:47:49.163 7776-8509 / com.androidbuts.uploadimage D / OkHttp: rXYZ
并且这种乱码继续存在很多行
D / OkHttp: - > END POST(14097字节正文)
我怎样才能看到有意义的原木猫?我想听听这个:
------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “flowChunkNumber”
1 ------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “flowChunkSize”
1048576 ------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “flowCurrentChunkSize”
23016 ------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “flowTotalSize”
23016 ------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “flowIdentifier”
23016-60x60music2_smalljpg ------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “flowFilename”
60x60music2_small.jpg ------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “flowRelativePath”
60x60music2_small.jpg ------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “flowTotalChunks”
1 ------ WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition:form-data; NAME = “文件”; filename =“blob”内容类型: 应用/八位字节流
------ WebKitFormBoundaryJDdhM3Si8enJZABA -
答案 0 :(得分:6)
The way to see the contents of a Multipart upload from Okttp and Retrofit is to use Stetho, by Facebook, and add StethoInterceptor to the Okhttp logger
https://github.com/facebook/stetho
It puts the Android app's network requests in your dev machine's chrome inspector.
答案 1 :(得分:-2)
它似乎是日志记录拦截器中的一个错误。
我能够解决这个问题购买调试日志拦截器。 问题是多部分的身体太大而且itercepter不能同时显示这么大的身体。它需要逐行打印。 这里是日志拦截器的修改版本,它与okhttp 3.4.1中的多部分一起使用:
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=16000,
input=True,
input_device_index=9,
frames_per_buffer=1024)
}