WWW in the editor

Hi all,

I have to post some data on a database in my local network from the editor calling something like “http://mylocalnetwork/Database.php?KEY=mykey&VALUE=myvalue

I’ve tried with the WWW class but it doesn’t seems to work inside the editor, also i don’t know how to get the results back as it looks like I can’t run coroutine in the editor and yield the WWW request (can I?)

The request is fired from a button in a CustomEditor script.

Any thoughts?

Thanks

I’ve just tried using HttpWebRequest/Response but i get this error

SecurityException: Unexpected error while trying to call method_GetSecurityPolicyBlocking : System.Security.SecurityException: Webrequest was denied
  at System.Net.WebConnection.LoggedThrow (System.Exception e) [0x00000] in <filename unknown>:0 
  at System.Net.WebConnection.CheckUnityWebSecurity (System.Net.HttpWebRequest request) [0x00000] in <filename unknown>:0 
System.Net.WebConnection.LoggedThrow (System.Exception e)
System.Net.WebConnection.CheckUnityWebSecurity (System.Net.HttpWebRequest request)
System.Net.WebConnection.Connect (System.Net.HttpWebRequest request)
Rethrow as WebException: Error: ConnectFailure (Unexpected error while trying to call method_GetSecurityPolicyBlocking : System.Security.SecurityException: Webrequest was denied
System.Net.WebConnection.LoggedThrow (System.Exception e)
System.Net.WebConnection.CheckUnityWebSecurity (System.Net.HttpWebRequest request) )
System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
System.Net.HttpWebRequest.GetResponse ()
Minigame.ExportMinigame () (at Assets/Scripts/Minigame.cs:165)
Minigame_Inspector.OnInspectorGUI () (at Assets/Editor/Minigame_Inspector.cs:11)
UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/842f9557127e852/Editor/Mono/Inspector/InspectorWindow.cs:495)
UnityEditor.InspectorWindow.OnGUI () (at C:/BuildAgent/work/842f9557127e852/Editor/Mono/Inspector/InspectorWindow.cs:190)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

is it not possible to use these functions?

edit:

adding a crossdomain.xml to the project doesn’t seems to help

crossdomain.xml must not be in the project but at www.yourdomain.com:80/crossdomain.xml

and to my knowledge (and going by a plentitude of threads), system.net.webrequest will not work anyway → WWW is the path to go

as I said WWW in the editor doesn’t work… or anyway i can’t wait for the request to finish and get the result as i can’t start a coroutine in the editor as far as i know (i hope i’m wrong)

I’ve already had a crossdomain in the root of my domain, any way to use the System.Net?

is it not possible at all to do an http request in editor?

EDIT:

ok it was my fault, the WWW is working in the editor.

how can i know when the request it’s done and use the results?
can i use something like a coroutine/WaitForSeconds in editor?

I don’t want to do something like

request = new WWW(url);
while (!request.isDone){}
// use request.text here

because it will block the editor and i could have to execute several requests all at the same time

Waiting for the result is normally done by using the WWW in a coroutine and then use yield wwwObject (or while (!wwwObject.isDone) yield return null; )

once thats through, look if it had an error (wwwObject.error) and otherwise use it

i know how it is normally done, the issue here is using the coroutine in the editor

You can’t use HTTPWebRequest on all Platforms, but you can use TCPClient and manually build your headers. We’ve slowly swapped over almost entirely to that (except for AssetBundles), due to some shortcomings of WWW.

thanks Ntero, i guess that’s the only option, WWW is really limiting what i can and i can’t do right now

In what form limiting? (I know it has limits but its targeted at what unity is, a game engine, not a general software platform so many of the limits are non impacting normally)

authentication and get/post of values currently

from the other thread in the support area:


even if I switch the platform the WWW request will still look for a crossdomain.xml

my file is in the server’s root folder but i keep getting a “was not found” error, if I set the editor setting to the same domain everything works fine but the domain for the WWW request is dynamic so i can’t keep changing manually the security emulation setting in the editor.

I’m doing requests with the url in the form “https://username:password@domain” and as I said everything works fine apart from the access to the crossdomain.xml file, maybe when the API try to access it it will fail without the authentication?

any idea on how can I get this working?

Hmm that sounds more like a bug that it asks for it on other platforms as it is webplayer related.
And there it will always ask for it you can’t get around it, WWW is actually the only way to even get away with crossdomain.xml, TCP / UDP not only requires crossdomain.xml but a socket server to be running on the other end, port 843 default or anything else otherwise - this is the same as for flash and silverlight too for example

Dreamora, personally our limitations were primarily: GET requests with headers and content, and being able to process data from the stream rather than getting a completely downloaded block, we were downloading updates on iOS, and needed to both minimize network requests (more requests means more time spent in latency, or hitting the DOS protection trigger on the server with too many simultaneous requests), and unzip/process the data as it came in so we didn’t get Memory issues.

Also we needed a special case of Blocking Request (WWW can do this on iOS, but not in Editor which was annoying).

yeah but i think it’s an auth issue, is like is not authorized to access the server and so i can’t find the crossdomain file.

i think with a tcp/udp connection i should be able to keep an authorized connection open and then the crossdomain check should just work

we will see anyway… unluckly I don’t have time to implement it right now so if anyone has any workaround is more than welcome

TCP will not even use crossdomain.xml. You either have a socket server running or it will fail flat out