3

我想发布一个对 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 客户端时,服务器端 PHP 运行良好。我尝试了很多解决方案,但我不知道如何让它工作。

4

0 回答 0