- Home /
UriFormatException
I am trying to use WWW to connect and download a text file from a web server however I keep getting this exception:
UriFormatException: Invalid URI: The format of the URI could not be determined. MonoForks.System.Uri..ctor (System.String uriString, Boolean dontEscape) MonoForks.System.Uri..ctor (System.String uriString) (wrapper remoting-invoke-with-check) MonoForks.System.Uri:.ctor (string) MonoForks.System.Windows.Interop.PluginHost.get_SourceUri () MonoForks.System.Windows.Browser.Net.CrossDomainPolicyManager.GetCachedWebPolicy MonoForks.System.Uri uri) UnityEngine.UnityCrossDomainHelper.GetSecurityPolicy (System.String requesturi_string, IPolicyProvider policyProvider) UnityEngine.UnityCrossDomainHelper.GetSecurityPolicy (System.String requesturi_string)
This only happens in any form of WebPlayer platform both inside and outside the editor however works perfectly fine when used in a standalone or IOS build. Following is the line that creates a new WWW request (dummy used for security).
WWW faqFile = new WWW("http://127.127.127.127/faq_text.txt?p=" + (int)(Time.time * 1000));
Where the value on the end is to make sure it returns a new version of the file each time not a cached version, and the dummy ip replaces the original ip.
When the original URL is entered in a web browser I am able to access the file. There is no issues with permissions and no problems with crossdomain.xml. This is all simply to do with the URI being used as far as I can tell.
Could anyone please shed some light on this issue?
Thanks
EDIT The issue appears to be with the editor emulation of the webplayer. The webplayer appears to be accessing the data fine now. Is there any work-arounds for the editor? It's kind of a pain to make a new build to test every change.
Thanks for all responses
Answer by Bunny83 · Dec 09, 2013 at 01:15 PM
First: From what place do you run your webplayer? Do you have it on your actual server and load the player via it's appropriate URL? If not the webplayer is required to check the crossdomain policy file on the server you try to contact.
Another thing is, we have no idea how your URL looks like. A common mistake is to try to add basic authorization information at the front of the URL (with @) but this is not supported by the http. Most browsers interpret this information and add an "Authorization" header to the request.
See this post for how you can add such an header:
http://forum.unity3d.com/threads/148521-Unity-WWW-and-htaccess
There might be something else wrong with your URL, however you stripped the most important part. Can you replace all elements you have in there with dummys and explaind each part?
Otherwise this leads nowhere...
I am running my WebPlayer from my development machine both in firefox and chrome browsers and from the unity editor WebPlayer emulation. I have a crossdomain policy file that should allow access from any domain.
The missing section is to hide the ip address that is being used as to let this out would be a security risk. The server that I am trying to access data from is on a separate network to my machine and so separate to the location of my WebPlayer.
The blank space it just the ip address of the server, the question has been updated to explain it a little better
Well, if it's just an IPv4 address, i have no idea what's wrong here. If it's an IPv6 address keep in $$anonymous$$d the URL format.
Just to be clear: The exception is thrown by the URI constructor, so your URI string has to be invalid. $$anonymous$$aybe some non-printable characters like "newline", "linefeed", ...
Try storing the request url in a string variable and do this Debug.Logs:
Debug.Log("URL: >" + yourURLstring + "<");
Debug.Log("URL length: " + yourURLstring.Length);
Check the debug log for line breaks or spaces.
Are you 100% sure that's how your url looks like? I can fully understand that you don't want to post your real IP / hostname / exact path / exactfilenames since that's all a potintial security risk. I just asked for a 1:1 replacement.
http://my.DomainName.com:3345/somesecret/path/importantFile.txt
A 1:1 replacement would be:
http://some.DomainName:somePortNumber/PathA/PathB/somefile.txt
It's difficult to help you with a malformed URI when we don't see the URI ;)
I have updated the format of the ip to show more correctly how it looks, however this might be redundant now since it has begun working in the webplayer builds It appears now to be an editor emulation problem now since it only fails in the editor.
Thanks for your help and quick responses :)
ps: i just visited my project graveyard and revived my old UA test project ;)
I've created this script:
public class TestURI : $$anonymous$$onoBehaviour
{
string log = "";
IEnumerator Start()
{
string url = "http://127.0.0.1/php/somefile.php?p=" + (int)(Time.time*1000 + Random.Range(0.0f,200.0f));
WWW w = new WWW(url);
yield return w;
log += w.text + "\r\n";
}
void OnGUI()
{
GUILayout.Label(log);
}
}
build a webplayer, started my xitami and loaded the webplayer file directly in my firefox. As result i see the output of my php file in the webplayer.
So i can't reproduce your problem. There has to be something wrong with your URI. You definately have just an iPv4 address as hostname? no custom port, no userinformation?
There is definitely no ports or user information required to access any of this data, it is being accessed using the exact same uri on IOS and standalone builds and it works perfectly fine in both editor and build.
It is just the editor emulation that is not working with it now.