I have a project where I communicate with some server over UnityWebRequest. In the editor everything works fine, but when I build it for Android and run it on my device I get an IOException sometimes while trying to send a web request. The exact error is as follows:
I create the request through:
UnityWebRequest.Post(url, data)
where data is my dictionary with data (and url is the url of course). For sending I use
public static IEnumerator SendRequestAsync(UnityWebRequest webRequest) {
// Don't chunk the data
webRequest.chunkedTransfer = false;
// Add API key to the header
webRequest.SetRequestHeader(API_KEY_HEADER_NAME, API_KEY);
// Send the request
yield return webRequest.SendWebRequest();
// From here on webRequest.isNetworkError is true when the error happend
// Some more processing of the request
}
If the error appears, then after my yield (line 9) the property isNetworkError of UnityWebRequest is set to true. I found some references to this kind of IOException, where people said they solved it by setting keep-alive to true (in native Android mostly), but it seems like UnityWebRequest doesn’t support this. If I create a new request to the same url and with the same data after the error, the request runs fine. Still I get the error often and I would love to know why it happens and how I maybe can prevent it.
Thank you guys in advance!
Is that all information that you can see in logcat?
Also, it would help if I could see more of the code that does the request, preferably with the data and all headers that you set.
java.io.IOException: unexpected end of stream on Connection{91.121.33.92:80, proxy=DIRECT@ hostAddress=91.121.33.92 cipherSuite=none protocol=http/1.1} (recycle count=0)
It only shows on android device (never on editor). I have a simple PUT method.
I noticed that when the PUT body is more than 1000 characters length, the error appears on android device and If body length is lass than 700 chars, the error never appears on android device. however It wont show on editor anyway at any circumstances.
I also noticed that despite the error the server gets the complete PUT body! I mean even when android device throw the error, the server has the complete body and responds correctly.