ProtocolException: unexpected end of stream
See original GitHub issueNot 100% reproduce depend on device (100% failed on vivo X20A version: 8.1.0).
Repro code
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Timber.plant(Timber.DebugTree())
net.setOnClickListener {
Thread {
Timber.w("network")
val request = Request.Builder()
.url("http://45.63.13.41:3000/playlist/detail?id=2451836751")
.get()
.addHeader("Cache-Control", "no-cache")
.addHeader("Accept-Encoding", "gzip, deflate")
.build()
val client = OkHttpClient()
val response = client.newCall(request).execute()
val body = response.body?.string()
Timber.w("response = " + body)
}.start()
}
}
}
Okhttp version: com.squareup.okhttp3:okhttp:4.1.0
StackTrace
E/AndroidRuntime: FATAL EXCEPTION: Thread-2
Process: me.gengjiawen.quickstart, PID: 4865
java.net.ProtocolException: unexpected end of stream
at okhttp3.internal.http1.Http1ExchangeCodec$FixedLengthSource.read(Http1ExchangeCodec.kt:392)
at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.kt:279)
at okio.Buffer.writeAll(Buffer.kt:1104)
at okio.RealBufferedSource.readString(RealBufferedSource.kt:194)
at okhttp3.ResponseBody.string(ResponseBody.kt:187)
at me.gengjiawen.switchdemo.MainActivity$onCreate$1$1.run(MainActivity.kt:29)
at java.lang.Thread.run(Thread.java:764)
Tried https://github.com/square/okhttp/issues/1490#issuecomment-78621872, but no luck.
Same code works on kotlin jvm. The url also works on curl, browser, Node.js.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
java.net.ProtocolException: unexpected end of stream
That exception is thrown by FixedLengthInputStream when the expected number of bytes (usually set in the content-length header of the response) ...
Read more >ProtocolException: Unexpected end of stream · Issue #7880
"Unexpected end of stream" normally means that the server response indicated it will provide a certain number of bytes (specified in the Content ......
Read more >Java.Net.ProtocolException: 'unexpected end of ... - MSDN
i try to input my Xamarin form app value to Sql server table using Asp.net Api but not working with "Java.Net.ProtocolException: 'unexpected end...
Read more >Multipart form file send writeFully fails with "java.net. ...
ProtocolException : unexpected end of stream". This issue was imported from GitHub issue: https://github.com/ktorio/ktor/issues/1829.
Read more >java.net.ProtocolException: unexpected end of stream
ProtocolException : unexpected end of stream. androidandroid-volleyokhttp. I am facing a strange issue, and I am not able to debug it out.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have contacted the support of my PaaS provider and they told me that this could be related to their reverse proxy. They have deployed a fix on their infrastructure and the issue seems to be solved.
yes, I am using Node.js.