问:
Using System.Net.WebRequest on an iOS project results in a NotSupportedException.
Why is this? This is really crippling from my point of view, and really limits what can be done with web services within a Unity game.
Please don't tell me to use WWW, I can't even read a HTTP status code that, or set headers...
Is there a way around this, or am I going to be forced to write my own WebRequest class?
答1:
Okey so I'm not telling you to use WWW, you can always use System.Net and TCPSockets to pull it off yourself. The HTTP protocol is extremely easy actually.
Alternatively a native code plugin to NSURLRequest allows you to do it too.
As for WWW:
WWW uses the native NSURLRequest on iOS, the best and most stable form of request you can do.
.Net.WebRequests are basically nowhere supported by Unity (aside of perhaps standalone win / osx) as it focuses its usage on WWW which complies to the limitations of the various platforms (aot on iOS, security sandbox on webplayer etc), a thing that is not the case for WebRequests.
答2:
OK. Here is one laptop-battery-charge worth of coding. It still has a way to go, but it is starting to work.
http://code.google.com/p/unityweb/source/checkout
This project provides a replacement HTTP.Request class for Unity3D, based on System.Net.TcpClient, using Asynchronous IO.
TODO: Add proxy support, Gzip decompression, documentation and examples.