- Home /
WWW.responseHeaders or WWW.error are not working on iOS when use invalid url
I have made a program to download a texture from WWW. In the Editor when the url does not exists it returns an error on WWW.error .
But when I try to use the same code in iOS, the WWW.error does not has nothing, and the WWW.responseHeaders is empty.
Just set headers on server side. See same question http://answers.unity3d.com/questions/594668/wwwprogress-not-working-on-android-ios-1.html
Answer by MasterFlu · Apr 09, 2015 at 11:36 AM
I ended up with the same problem, everything was empty, the www.error, www.text, www.responseHeaders.
But I have found/created a workaround. For iOS and all other platform you can access the responseHeadersstring by using Reflections. the string mostly isn´t empty also the www.error, www.text, www.responseHeaders are. After www.isDone du the following
var rhsPropInfo = typeof(WWW).GetProperty("responseHeadersString",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
if (rhsPropInfo != null)
{
#if !UNITY_IOS
var headersString = rhsPropInfo.GetValue(www, null) as string;
#else
//This is a workaround for getting Reflactions to work with iOS
var headersString = rhsPropInfo.GetGetMethod(true).Invoke(www, null);
#endif
string[] lines = headersString.ToString().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var l in lines)
{
//Filter your string for what you want
}
Hope this will solve the issue and sorry for my English
Answer by kixorz · Sep 11, 2012 at 01:11 AM
Unity looked into it and said that it's not a bug, but a 4.0 feature. (WTF moment) https://fogbugz.unity3d.com/default.asp?440636_8ev903h148eg7enq
We had to hack our web server to send some of the headers in the response body.
Answer by PanCrucian · Apr 11, 2015 at 05:52 PM
Just set headers on server side. See same question http://answers.unity3d.com/questions/594668/wwwprogress-not-working-on-android-ios-1.html