System.Net features not supported - how to handle cookies?

Hi all,

I’m trying to make a web service call using System.Net.HttpWebRequest.Create()

It’s all working perfectly in the editor, but when I create a build (standalone, not web player), I get this error in the player logs:

NotSupportedException: https://… [URL GOES HERE - REMOVED AS IT HAS MY LOGIN DETAILS IN IT!]
at System.Net.WebRequest.GetCreator (System.String prefix) [0x00000] in :0
at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in :0
at System.Net.WebRequest.Create (System.String requestUriString) [0x00000] in :0
at WebAPI.Authenticate () [0x00000] in :0
at WebAPI.GUIDrawSignInPanel () [0x00000] in :0
at WebAPI.OnGUI () [0x00000] in :0

The reason I am not using the WWW class is because I need to get a cookie from the header of the first authentication web service call and pass it back in the header of subsequent service calls. It doesn’t seem possible to do this with the Unity WWW or WWWForm classes – unless I’m wrong.

Any help or suggestions as to how to get around this would be appreciated.

Thanks in advance. :slight_smile:

The WWWForm class does allow you to get headers (which would include cookies) but I guess this isn’t appropriate for what you are doing. Have you tried setting the .NET compatibility level to 2.0 rather than the default 2.0 subset value? (Menu: Edit > Project settings > Player) I’m not entirely sure but the class you need may be available in the full .NET library and discarded for the subset.

Check if its actually more that the corresponding assembly is not present in the build. The editor can use them in such a case but does not include them in the build.

For standalone there shouldn’t be a reason it wouldn’t work (for webplayer and iOS its not possible to use it at all)

Hey guys, thanks for the replies.

@andeeee You’re right, I did see WWWForm.headers in the docs, but from what I read this doesn’t allow me to get the cookie from a the response of the initial web service (though potentially could be used to set a cookie in the header for any further requests). And yah, I checked that I am using .Net 2.0, not the subset.

@dreamora Isn’t System.Net part of System.dll? If so, that’s definitely in the build. I thought the same too – that it would work in the standalone, I don’t need it to work in iOS or a webplayer.