I’ve stumbled upon an error I just can’t understand. When doing a WWW to a certain php I get:
Fatal Error : Error: Error #2030: End of file was encountered.
at flash.net::URLStream/readBytes()
at com.unity::UnityNative$/Ext_UrlStream_CopyBytes()
at com.unity::UnityNative$/_ZN8WWWFlash12DoneCallbackEii()
at com.unity::UnityNative$/WWWFlashCallbackSize()
at com.unity::URLStreamHandler/onURLLoaderComplete()
So I stripped the php down to just returning the string “0” and the WWW function to just:
WWW www = new WWW("http://195.178.163.254/summergames/test.php");
yield return www;
print(www.text);
But I’m still getting the same error.
Now to the real weird part. I’m not getting any error when posting to some of our other php’s.
Btw, the error only shows when exporting to Flash. Works just fine in the editor.
Loading test.php with URLLoader or URLStream in Flash does not generate the error either.
Thanks for reporting this. I’ve raised a bug report for this issue.
In the meantime, you can work around this issue by doing your web request in pure AS3 inside your Unity project:
Create an AS3 class in your project which has a function to perform the web request and store the response. Put this class in a folder called ActionScript.
Now create a matching class in C# and add the [NotConverted] and [NotRenamed] attributes so that this class will not be converted to AS3 at runtime.
In your project, assuming the C#/AS3 classes have the same API, you should be able to create a new instance of this class and use its web request function.
I’ve hacked together a very quick example (attached) which works for your test.php service. Hopefully you can use this to fix your project.
awesome. thanks so much Cat.
just having problems when i use the class in that i want to modify the WWWCaller class in actionscript but unity is giving me compile time errors saying
error CS1061: Type WWWCaller' does not contain a definition for DoUserRequest’ and no extension method DoUserRequest' of type WWWCaller’ could be found (are you missing a using directive or an assembly reference?)
either that or pass a url through in DoWebRequest(“http://url”).
How do i go about compiling the new WWWCaller class in actionscript within the Unity stuff or should it happen automatically.
For the benefit of anyone that is wondering how to pass an url parameter to the DoWebRequest in the Action Script linked above (as I was), you can make the following changes.
In WWWCaller.as:
var address:String;
public function DoWebRequest(address) : void
{
request = new URLRequest();
request.url = address;
In TestWWW.cs:
#else
WWWCaller wwwCaller = new WWWCaller();
wwwCaller.DoWebRequest("http://whatever.etc");
And most importantly, in WWWCaller.cs:
public void DoWebRequest(string address)
Without the last change, the build will not compile because it seems the whole point of WWWCaller.cs is to act as a placeholder for WWWCaller.as, which Unity will not check for errors. However, if Unity finds errors in WWWCaller.cs, it will not compile. This puzzled me for the longest time, but now it makes complete sense.