Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Android改造多部分请求协议异常_Php_Android_Retrofit_Okhttp_Protocolexception - Fatal编程技术网

Php Android改造多部分请求协议异常

Php Android改造多部分请求协议异常,php,android,retrofit,okhttp,protocolexception,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

我想发表一篇文章,对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);
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工作得非常好。我尝试了许多解决方案,但我不知道如何让它发挥作用

 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)