I´m using WWW class to POST data but I’m having problem with it. The problem is related to the size of “postData” and server exceptions.
My script needs to work like this: I’ll post a json and if the token is valid the server returns another json.
The problem:
When I send a “postData” with size GREATER than 1024bytes and my server needs to throw an exception like 401, the return of WWW is always “SUCCESS” and my “request.size” returns 0 bytes. I don´t receive the HTTPStatusCode 401 and neither the “request.error”.
When my “postData” is LESS than 1024bytes the return works well, I receive the “request.error” with the exception when my server throws it.
Both “postData” sizes gives “request.success +right json” when the token is valid.
Is this normal? Am I doing anything wrong? Do I need to configure something on the server sided?
I’m using Unity 4.6.1, but I tested it on the last Unity 4.5.x and the problem occurs on that version too.
My server uses ASP.NET WebAPI.
Note: On all situations the flow on server is the same.
Thanks.
My code:
byte[ ] bytesUp = Encoding.UTF8.GetBytes(“SOME TEXT TO BYTES”);
Dictionary<string, string> postHeader = new Dictionary<string, string>();
postHeader.Add(“Content-Type”, “application/json”);
postHeader.Add(“tokenauth”, tokenVariable);
requestLogin = new WWW (urlLogin, bytesUp, postHeader);
yield return requestLogin;
if (!String.IsNullOrEmpty(requestLogin.error)) {
Debug.Log("Request Error : ");
Debug.Log(requestLogin.error);
}
else {
Debug.Log("Request Success : ");
Debug.Log("Returned Size : " + requestLogin.size);
Debug.Log("Returned Data : " + requestLogin.text);
}