2016-05-25 8 views
1

同じ接続(okhttpclientは私のニーズに合ったもの)を使用して一連の呼び出しを行う必要がありますそのうちの一つは、204のステータスコード(NO体)を返したが、成功して「204呼出し」の後:同じ接続を使用して "204 NO-CONTENT"応答の後、OkHttp "java.net.ProtocolException:予期しないステータス行:nullHTTP/1.1 200 OK"

java.net.ProtocolException: Unexpected status line: nullHTTP/1.1 200 OK 
at okhttp3.internal.http.StatusLine.parse(StatusLine.java:69) 
at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:184) 
at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:125) 
at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:775) 
at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:86) 
at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:760) 
at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:613) 
at okhttp3.RealCall.getResponse(RealCall.java:244) 
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201) 
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163) 
at okhttp3.RealCall.execute(RealCall.java:57) 
at it.test.Main.main(Main.java:48) 

リクエストヘッダ「接続:閉じる」を使用して(そう接続を再利用しない)問題が発生しません。

これは、プロンプトを報告する作業主です。それは、誰かが私が見つからないか、それはバグである場合てる何を理解私を助けてもらえますか?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(); 
} 

をokHttp使用していますか Tnx

答えて

1

あなたのウェブサーバーは、以前の応答がボディーを持っていないと主張しているようですが、4文字のボディー "ヌル"を書いているようです。問題をウェブサーバの保守担当者に報告してください。問題を修正する必要があります。

+0

あなたの返信はTnxです。 204リクエストのレスポンスボディの上にあるコードを実行すると空(0バイト)なので、 "null"がどこにあるのか分かりません... okhttpクライアントはデフォルトで204長さのボディを与えますか?それとも実際にストリームを見ていますか? – CarloS

+0

パケットアナライザ(wireshark)を使うと、 "null"が見えます...そうです:)もう一度Tnx – CarloS