Volley + OkHttp on Android gives error on status 200 response

假如想象 提交于 2019-12-07 05:04:49

问题


When I make my request with only Volley everything goes well and my StringRequest goes to onResponse.

But when I switch to Volley + Okhttp combination, my request goes through, I receive the same response as before but then I get the following error message:

E/Volley﹕ [122319] BasicNetwork.performRequest: Unexpected response code 200 for <my request url> java.io.IOException: closed com.android.volley.NetworkError: java.io.IOException: closed at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:182) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114) Caused by: java.io.IOException: closed at okio.RealBufferedSource$1.read(RealBufferedSource.java:345) at java.io.InputStream.read(InputStream.java:162) at com.android.volley.toolbox.BasicNetwork.entityToBytes(BasicNetwork.java:254) at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:130)             at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)

Im using this https://gist.github.com/bryanstern/4e8f1cb5a8e14c202750 for my OkHttpStack for Volley.


回答1:


I haven't had too much time to investigate but I was running into the same issue when using the emulator connected through a proxy (Charles). For me the problem goes away when I test without a proxy or on device.




回答2:


This exact same problem happened to me when using the start and stop methods of the RequestQueue. It was pointed out in many popular blogs that the RequestQueue should be stopped when user is flinging to ensure there's no jerking. However when you call stop, all RequestQueue's requests are stopped, even the ones which were already doing network call. The above exception happened when these requests are stopped preliminarily. Not calling the stop function solved the problem for me.




回答3:


For those people using a Proxy (in my case Charles) besides configuring your proxy in Settings it is necessary to configure also your proxy in the Android Emulator.

So, here is my configuration in Settings Emulator

And this are the steps to configure the proxy using wifi in Android Emulator

  1. Settings
  2. Network & Internet
  3. Wi-Fi
  4. Android Wifi
  5. Click on Setting icon
  6. Click Edit icon

  1. Configure your proxy



来源:https://stackoverflow.com/questions/32038328/volley-okhttp-on-android-gives-error-on-status-200-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!