I'm creating an application in Unity3d that needs to download images from a database via a PHP file, for various reasons I decided to use System.Net.WebClient instead of the unity class WWW and after several attempts it works with this code.
idEvent = 3; //exemple
string responsefromserver = "";
Uri URL = new Uri("http://******.000webhostapp.com/ImEvents.php");
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["selectedId"] = idEvent;
webClient.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
{
Debug.Log ( string.Format(" downloaded {0} of {1} bytes.",
e.BytesReceived,
bytes //e.TotalBytesToDownload returns always -1 so this value is given by a variable
));
};
webClient.UploadValuesCompleted += (object sender, UploadValuesCompletedEventArgs e) =>
{
responsefromserver = Encoding.UTF8.GetString(e.Result);
webClient.Dispose();
};
webClient.UploadValuesAsync(URL, "POST", formData);
the e.TotalBytesToDownload returns always -1 but I noticed after various research that this is due to other factors and since it is an information that I can recover in another way this does not matter to me ... The problem is that e.BytesRecived immediately rises to figures around 3000-4000 bytes and then RETURN BACK and give me all values that oscillate between 1444 and 1452 bytes ...
THIS DOES NOT HAVE ANY SENSE!!!
here is an example of the Log
downloaded 6828 of 39680 bytes.
downloaded 2644 of 39680 bytes.
downloaded 1452 of 39680 bytes.
downloaded 1447 of 39680 bytes.
downloaded 1444 of 39680 bytes.
downloaded 1452 of 39680 bytes.
ecc...
So my question is:
Why e.BytesReceived does not give me the real number of bytes recived (which should only increase up to the file size and not oscillate between 1444 and 1452 bytes)
(If it is important, this code is inside of an IEnumerator function...)
I apologize for my english