I have been fighting with UnityWebRequest for two days now over just simple shit. For example:
I have my game connect to a web server and get a JSON response verifying the server is up.
url += "api/hlogin/connectionCheck/";
In the editor, this works. Build and upload the game to the same server, this works.
I then have the game then connect to the server to verify a login and get a JSON response… same code mind you.
url += "api/hlogin/doConnect/";
In the editor, this works. Build and upload the game to the same server, 404 error.
How about this one for some debugging fun:
Somehow, this piece of trash managed to get BOTH the 404 error page AND the JSON response from the server, mash them both together in the same downloadHandler.text and promptly spit back a 404 error. And that’s with just one request (yea, I set up a counter to make sure this thing wasn’t doing 2 requests and gluing different results together).
More? Ok.
I do a web request to the server and it grabs the JSON just fine. And gives a 404 error in isHttpError. Wait a minute, how can it grab the page AND say it doesn’t exist?!?
MORE??? Sure.
WTF is a HTTP error code 0? I looked through RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1 and unless I’m blind an illiterate those error codes start at 100. But does UnityWebRequest spit out a 0 when it wants to? Yep, sure does. I’ve seen it. “Unknown Error” Really? It’s UNKNOWN??? Ok. If you write code and you put in an error handler then you pretty much know when and were the error occurs unless you’re just being damned lazy and classify EVERYTHING as an unknown error. Was it in sending the request? No internet connection? Was it in the server? Did it give a 500 error response? Was it in the GD SSL certificate? UNKNOWN doesn’t tell me CRAP!
And, here’s one more for the road. If I do this, UnityWebRequests spits out a 404 error:
if (connectRequest.isNetworkError || connectRequest.isHttpError)
{ }
But, if I ignore the 404 error and do this:
if (connectRequest.isNetworkError)
{ }
the page loads just fine. Make sense? Nope.
I want to program Unity in PHP. 5 minutes and I’d have a Curl request with none of these stupid problems.