在調(diào)用go
語言編寫的server
進(jìn)行下載文件時出現(xiàn)
java.net.ProtocolException: unexpected end of stream
at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:421)
java.io.IOException: unexpected end of stream
at com.squareup.okhttp.internal.http.HttpConnection$ChunkedSource.read(HttpConnection.java:467)
原因:
go server
響應(yīng)時的邏輯是
n, err := io.Copy(w, f)
而go http
的底層tcp
連接設(shè)置了(timeout)
超時時間,由于文件過大或者并發(fā)過大,導(dǎo)致流沒有復(fù)制完医增,所以出現(xiàn)上述報錯
出現(xiàn)第一種報錯是因為故河,在go server
端在上述代碼前設(shè)置了content-length
而因為有content-length
榄攀,所以調(diào)用read
的具體方法不同
參見http://stackoverflow.com/questions/26096944/when-responding-using-io-copy-who-should-be-responsible-for-the-error