Hello,
Welcome to our Microsoft Q&A platform!
Java.IO.EOFException: \n not found: size=0 content=...
If you get EOF exception, When the interval between two requests exceeds the keep-alive timeout configured on the server side, the server side will actively close the current connection. The Okhttp connection pool ConnectionPool default timeout time is 5min, which means that the connection in the connection pool will be reused first, but the server has already taken the initiative close, causing the input stream to be interrupted, and then throwing an EOF exception. Among them, keep-alive: the maximum interval between two requests. If this interval is exceeded, the server will actively close the connection, mainly to avoid re-establishing the connection and saving server resources.
When creating an OkHttpClient instance, you only need to set ** RetryOnConnectionFailure(true);** to true. When an EOF exception is thrown, let it continue to execute the realChain.proceed method.
Or store information to the location storage, If navigate pages , please compare two connection times, if within default timeout time, use the location information.
====================
Update==========================
I find a new way to fix it, please try to achieve the Httpclient request with try catch method. if we get Java.IO.IOException: unexpected end of stream.. exception, we load the data from the local storage, I use sharepreference to make a test. If the HttpStatusCode.OK, we can store the data to the local storage when get the Java.IO.IOException: unexpected end of stream.., please note, I cannot get this execption to make a test, so the exception's string is wrong, you can debug it then get the correctly execption.
var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(App.HttpClient_TimeOut);
client.BaseAddress = new Uri("https://www.domain.com/get.php");
string result;
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("id", id),
});
try
{
var response = await client.PostAsync("https://www.domain.com/get.php", content);
if (response.StatusCode == HttpStatusCode.OK)
{
//store the information to the local file or share-preference
result = await response.Content.ReadAsStringAsync();
Preferences.Set("my_key", result);
}
}
catch (Exception exc) {
if (exc.Message == "Java.IO.IOException: unexpected end of stream..")
{
result= Preferences.Get("my_key", "default_value");
}
//
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.