http - OkHttp "java.net.ProtocolException: Unexpected status line: nullHTTP/1.1 200 OK" after a "204 NO-CONTENT" response using same connection -
i need sequence of calls using same connection (okhttpclient fits needs) , 1 of them returns 204 status code (no body), after "204 call" success:
java.net.protocolexception: unexpected status line: nullhttp/1.1 200 ok @ okhttp3.internal.http.statusline.parse(statusline.java:69) @ okhttp3.internal.http.http1xstream.readresponse(http1xstream.java:184) @ okhttp3.internal.http.http1xstream.readresponseheaders(http1xstream.java:125) @ okhttp3.internal.http.httpengine.readnetworkresponse(httpengine.java:775) @ okhttp3.internal.http.httpengine.access$200(httpengine.java:86) @ okhttp3.internal.http.httpengine$networkinterceptorchain.proceed(httpengine.java:760) @ okhttp3.internal.http.httpengine.readresponse(httpengine.java:613) @ okhttp3.realcall.getresponse(realcall.java:244) @ okhttp3.realcall$applicationinterceptorchain.proceed(realcall.java:201) @ okhttp3.realcall.getresponsewithinterceptorchain(realcall.java:163) @ okhttp3.realcall.execute(realcall.java:57) @ it.test.main.main(main.java:48)
using request header "connection: close" (so not reusing connection) problem doesn't occur.
this working main reporting proplem. uses okhttp v3.3.0 , okio v1.8.0
public static void main(string[] args) { try { string url200 = "http://www.cmsservice.provahosting.it/index.php?option=com_cmsmanager&key=ca25131a2f77fb2b80d82e63412fdc13&debug=1&cmd=status"; string url204 = "http://www.cmsservice.provahosting.it/index.php?option=com_cmsmanager&key=ca25131a2f77fb2b80d82e63412fdc13&debug=1&cmd=getupdates"; okhttpclient client = new okhttpclient.builder() .connecttimeout(20, timeunit.seconds) .readtimeout(20, timeunit.seconds).build(); //first request request request = new request.builder() .url(url200)/*.addheader("connection", "close")*/ .build(); response response = client.newcall(request).execute(); system.out.println(response.code()+">>>>" + response.body().string().getbytes().length + "<<<<"); response.body().close(); //second request request request2 = new request.builder() .url(url204)/*.addheader("connection", "close")*/ .build(); response = client.newcall(request2).execute(); system.out.println(response.code()+">>>>" + response.body().string().getbytes().length + "<<<<"); response.body().close(); //third request request request3 = new request.builder() .url(url200)/*.addheader("connection", "close")*/ .build(); response = client.newcall(request3).execute(); system.out.println(response.code()+">>>>" + response.body().string().getbytes().length + "<<<<"); response.body().close(); } catch (exception e) { e.printstacktrace(); }
could me understanding i'm missing or if bug? tnx
looks webserver claiming prior response has no body, writing 4 character body “null”. report problem webserver’s maintainers , should fix it.
Comments
Post a Comment