Search Unity

Why is System.Net.WebRequest unsupported in iOS?

Discussion in 'iOS and tvOS' started by simonwittber, Jan 12, 2011.

  1. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    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?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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.
     
  3. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    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.
     
  4. franky303

    franky303

    Joined:
    Aug 27, 2012
    Posts:
    10
    Hello Simon, thanks for sharing this! - Will this also be working when exporting to iOS ?
     
  5. eppz

    eppz

    Joined:
    Aug 2, 2014
    Posts:
    172
    @Dreamora Hi, could you please confirm if UnityWebRequest is processing request on a background thread?

    I can see that it is split to IEumerator yields, but I want to know if there is there a separate background thread is involved? The predecessor (WWW) was also Coroutine based, but still the calls between yields freezed the main thread. It is really annoying, when a web service is lagging / not available.

    Has UnityWebRequest fixed this?
     
    Last edited: Jan 25, 2018