Android改造多部分请求ProtocolException

时间:2016-06-07 21:12:23

标签: php android retrofit okhttp protocolexception

我想通过改造SlimApi端点来发帖。但每当我提出要求时,我都会得到:

java.net.ProtocolException: expected 638 bytes but received 2048

我的界面看起来像这样,

@Multipart
@PUT("pictures")
Call<JSONObject> putImages(@Header("authorization") String apiKey,
                          @Part("view_time") RequestBody viewtime,
                          @Part("receiver") RequestBody receiver,
                          @Part("picture\"; filename=\"fileUpload.jpg\" ") RequestBody fileToUpload);

我发布的RequestBodys是这些:

RequestBody fbody = RequestBody.create(MediaType.parse("image/jpeg"), new File(filePath));
RequestBody viewtime = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(10));
RequestBody reciever = RequestBody.create(MediaType.parse("text/plain"), "1234567890");

apiKey是一个简单的字符串。所有路径都有效并经过双重检查。现在,当我开始请求时,我得到以下StackTrace:

 D/OkHttp: --> PUT http://myserver/myapi/v1/pictures http/1.1
 D/OkHttp: Content-Type: multipart/form-data; boundary=37f9d73a-b60e-4cde-9c43-180e7308d061
 D/OkHttp: Content-Length: 638
 D/OkHttp: authorization: aa3bbdb.................... //This one is correct, checked that in database
 D/OkHttp: --> END PUT (638-byte body)
 D/FirebaseCrashApiImpl: throwable java.net.ProtocolException: expected 638 bytes but received 2048
 W/System.err: java.net.ProtocolException: expected 638 bytes but received 2048
 W/System.err:     at okhttp3.internal.http.Http1xStream$FixedLengthSink.write(Http1xStream.java:283)
 W/System.err:     at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
 W/System.err:     at okio.RealBufferedSink.writeAll(RealBufferedSink.java:104)
 W/System.err:     at okhttp3.RequestBody$3.writeTo(RequestBody.java:118)
 W/System.err:     at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.java:171)
 W/System.err:     at okhttp3.MultipartBody.writeTo(MultipartBody.java:113)
 W/System.err:     at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:704)
 W/System.err:     at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563)
 W/System.err:     at okhttp3.RealCall.getResponse(RealCall.java:241)
 W/System.err:     at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
 W/System.err:     at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
 W/System.err:     at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
 W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
 W/System.err:     at okhttp3.RealCall.access$100(RealCall.java:30)
 W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
 W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
 W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
 W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
 W/System.err:     at java.lang.Thread.run(Thread.java:818)

当我使用手动REST客户端时,Serversided PHP正常运行。我尝试了很多解决方案,但我无法弄清楚如何让它发挥作用。

0 个答案:

没有答案