Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
Android 改装2补丁请求不响应车身_Android_Retrofit2_Patch - Fatal编程技术网

Android 改装2补丁请求不响应车身

Android 改装2补丁请求不响应车身,android,retrofit2,patch,Android,Retrofit2,Patch,我正在开发一个具有一些端点的应用程序。总的来说,补丁请求在填充正文时不会回调,并且会出现超时错误。此事件仅发生在修补程序请求和其他方法(如GET、POST、PUT和DELETE)正常工作时。另一件事是这些端点在Postman中都可以正常工作 我的服务之一 public interface ApiService { @Headers({"Accept: application/json;version=0.1.1", "Content-Type: applicat

我正在开发一个具有一些端点的应用程序。总的来说,补丁请求在填充正文时不会回调,并且会出现超时错误。此事件仅发生在修补程序请求和其他方法(如GET、POST、PUT和DELETE)正常工作时。另一件事是这些端点在Postman中都可以正常工作

我的服务之一

public interface ApiService {

    @Headers({"Accept: application/json;version=0.1.1",
            "Content-Type: application/json; charset=utf-8"})
    @PATCH("api/club/product/{id}/")
    Call<ResponseBody> requestEditProducts(@Header ("Authorization") String token,
                                           @Body RequestBody body,
                                           @Path("id") int id);
}
一个呼叫示例

JSONObject object = new JSONObject();
        try {
            object.put("name", "new name");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), object.toString());

        Call<ResponseBody> call = RetrofitClient.getInstance().create(ApiService.class)
                .requestEditProducts(token, requestBody, id);
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                Log.d("PATCH_REQUEST", "code: " + response.code() +
                        "             body: " + response.body());
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                t.printStackTrace();
            }
        });
JSONObject object=new JSONObject();
试一试{
对象。放置(“名称”、“新名称”);
}捕获(JSONException e){
e、 printStackTrace();
}
RequestBody RequestBody=RequestBody.create(okhttp3.MediaType.parse(“application/json;charset=utf-8”)、object.toString();
Call Call=client.getInstance().create(ApiService.class)
.requestEditProducts(令牌、requestBody、id);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
Log.d(“补丁请求”,“代码:”+响应.code()+
“body:+response.body());
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
t、 printStackTrace();
}
});
结果如何

D/OkHttp: --> PATCH http://beta.nsme.com/api/club/product/9/
D/OkHttp: Content-Type: application/json; charset=utf-8
D/OkHttp: Content-Length: 41
D/OkHttp: Accept: application/json;version=0.1.1
D/OkHttp: Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxx
D/OkHttp: {"name":"new name"}
D/OkHttp: --> END PATCH (41-byte body)
D/OkHttp: <-- HTTP FAILED: java.net.SocketException: Socket closed
W/System.err: java.io.InterruptedIOException: timeout
W/System.err:     at okhttp3.internal.connection.Transmitter.timeoutExit(Transmitter.java:109)
W/System.err:     at okhttp3.internal.connection.Transmitter.maybeReleaseConnection(Transmitter.java:302)
W/System.err:     at okhttp3.internal.connection.Transmitter.noMoreExchanges(Transmitter.java:267)
W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:237)
W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:172)
W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err:     at java.lang.Thread.run(Thread.java:818)
W/System.err: Caused by: java.net.SocketException: Socket closed
W/System.err:     at libcore.io.Posix.recvfromBytes(Native Method)
W/System.err:     at libcore.io.Posix.recvfrom(Posix.java:185)
W/System.err:     at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:250)
W/System.err:     at libcore.io.IoBridge.recvfrom(IoBridge.java:553)
W/System.err:     at java.net.PlainSocketImpl.read(PlainSocketImpl.java:485)
W/System.err:     at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
W/System.err:     at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
W/System.err:     at okio.Okio$2.read(Okio.java:140)
W/System.err:     at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
W/System.err:     at okio.RealBufferedSource.indexOf(RealBufferedSource.java:358)
W/System.err:     at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:230)
W/System.err:     at okhttp3.internal.http1.Http1ExchangeCodec.readHeaderLine(Http1ExchangeCodec.java:242)
W/System.err:     at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.java:213)
W/System.err:     at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.java:115)
W/System.err:     at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:94)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:43)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
W/System.err:     at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:212)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
W/System.err:   ... 5 more
D/OkHttp:-->修补程序http://beta.nsme.com/api/club/product/9/
D/OkHttp:内容类型:application/json;字符集=utf-8
D/OkHttp:内容长度:41
D/OkHttp:Accept:application/json;版本=0.1.1
D/OkHttp:授权:持票人XXXXXXXXXXXXXXXXXXXXXXXX
D/OkHttp:{“名称”:“新名称”}
D/OkHttp:-->结束修补程序(41字节正文)

D/OkHttp:问题似乎在于您重新创建了改造。您必须将此创建包括到您的singleton中:

public class RetrofitClient {

    private static ApiService api;

    public static ApiService getInstance() {
        if (api == null) {

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            httpClient.addInterceptor(logging);
            httpClient.connectTimeout(120, TimeUnit.SECONDS);
            httpClient.callTimeout(120, TimeUnit.SECONDS);
            httpClient.readTimeout(120, TimeUnit.SECONDS);
            httpClient.writeTimeout(120, TimeUnit.SECONDS);
            httpClient.retryOnConnectionFailure(true);

            retrofit = new Retrofit.Builder()
                    .baseUrl(Consts.BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(httpClient.build())
                    .build();
            api = retrofit.create(ApiService.class)
        }
        return api;
    }
}
然后像这样打电话:

Call<ResponseBody> call = RetrofitClient.getInstance().create(ApiService.class).requestEditProducts(token, requestBody, id);
call.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            Log.d("PATCH_REQUEST", "code: " + response.code() +
                    "             body: " + response.body());
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            t.printStackTrace();
        }
});
Call Call=reformationclient.getInstance().create(ApiService.class).requestEditProducts(令牌、请求主体、id);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
Log.d(“补丁请求”,“代码:”+响应.code()+
“body:+response.body());
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
t、 printStackTrace();
}
});

问题似乎在于您重新创建了改装。您必须将此创建包括到您的singleton中:

public class RetrofitClient {

    private static ApiService api;

    public static ApiService getInstance() {
        if (api == null) {

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            httpClient.addInterceptor(logging);
            httpClient.connectTimeout(120, TimeUnit.SECONDS);
            httpClient.callTimeout(120, TimeUnit.SECONDS);
            httpClient.readTimeout(120, TimeUnit.SECONDS);
            httpClient.writeTimeout(120, TimeUnit.SECONDS);
            httpClient.retryOnConnectionFailure(true);

            retrofit = new Retrofit.Builder()
                    .baseUrl(Consts.BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(httpClient.build())
                    .build();
            api = retrofit.create(ApiService.class)
        }
        return api;
    }
}
然后像这样打电话:

Call<ResponseBody> call = RetrofitClient.getInstance().create(ApiService.class).requestEditProducts(token, requestBody, id);
call.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            Log.d("PATCH_REQUEST", "code: " + response.code() +
                    "             body: " + response.body());
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            t.printStackTrace();
        }
});
Call Call=reformationclient.getInstance().create(ApiService.class).requestEditProducts(令牌、请求主体、id);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
Log.d(“补丁请求”,“代码:”+响应.code()+
“body:+response.body());
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
t、 printStackTrace();
}
});


最后,经过大量测试,我们发现错误是由于ISP代理问题造成的。它会导致身体的补丁方法出现问题。

最后,经过大量测试,我们发现错误是由于ISP代理问题造成的。这会导致正文的修补方法出现问题。

requestEditProducts和patchMessage是不同的调用。请您在示例中发布相同的请求。另外,我猜您需要您的身份验证令牌来请求patchMessage。我犯了一个错误,对不起。这篇文章已经编辑过了。不幸的是,后端人员不允许我共享令牌和URL@eugenetroyanskii,因为您有3个参数requestEditProducts(@Header(“Authorization”)字符串令牌、@Body RequestBody、@Path(“id”)int id);当你调用这个方法时,你只放了2个requestEditProducts(requestBody,id);你不能编译这个。啊,你是对的,我忘了。编辑。非常感谢关于find Errors@EugeneTroyanskiiDoes在postman中有效吗?requestEditProducts和patchMessage是一个不同的调用。请您在示例中发布相同的请求。另外,我猜您需要您的身份验证令牌来请求patchMessage。我犯了一个错误,对不起。这篇文章已经编辑过了。不幸的是,后端人员不允许我共享令牌和URL@eugenetroyanskii,因为您有3个参数requestEditProducts(@Header(“Authorization”)字符串令牌、@Body RequestBody、@Path(“id”)int id);当你调用这个方法时,你只放了2个requestEditProducts(requestBody,id);你不能编译这个。啊,你是对的,我忘了。编辑。非常感谢关于find errors@EugeneTroyanskiiDoes它在postman中工作吗?连接错误不会只影响补丁请求:顺便说一句,你忘了为internet添加权限吗?你在开玩笑吗?:\当然,我添加了互联网许可。但我真的不知道为什么所有的请求在SIM卡数据中都能正常工作,而在我的wifi模式下,只是补丁请求不能工作@Eugenetroyanskii连接错误不能只影响修补程序请求:顺便说一句,你忘了添加internet权限吗?你在开玩笑吗?:\当然,我添加了互联网许可。但我真的不知道为什么所有的请求在SIM卡数据中都能正常工作,而在我的wifi模式下,只是补丁请求不能工作@Eugenetroyanskisorry,问题是由ISP代理服务器引起的。抱歉,问题是由ISP代理服务器引起的。