- Home /
Prevent UnityWebRequest.url from decoding string
I'm trying to make a request to a url that contains %2F as part of the url
var myUrl = "http://mydatabase.com/coolFolder%2FcoolFile";
However, when I enter this url in to a UnityWebRequest either via the constructor:
var request = new UnityWebRequest(myUrl);
or via the property:
request.url = myUrl;
the url becomes
"http://mydatabase.com/coolFolder/coolFile"
And that will not let me access the proper url, so my request will fail. I assume Unity is decoding that behind the scenes and I cannot figure out any way to bypass that.
Help?
lol!
ugh, what a drag.
maybe you could try coolFolder%252fcoolFile
?
%25 is the encoding for %
.
I just tried that, elenzil, and it didn't work, unfortunately. It seems that URI only decodes %2F and %2E automatically because coolFolder%252fcoolFile
stayed coolFolder%252fcoolFile
.
string url1 = "http://example.com/" + "coolFolder/coolFile";
var uwr1 = UnityWebRequest.GetAssetBundle(url1);
Debug.Log(url1 + " -> " + uwr1.url);
// http://example.com/coolFolder/coolFile -> http://example.com/coolFolder/coolFile
string url2 = "http://example.com/" + "coolFolder/coolFile".Replace("/", "%2F");
var uwr2 = UnityWebRequest.GetAssetBundle(url2);
Debug.Log(url2 + " -> " + uwr2.url);
// http://example.com/coolFolder%2FcoolFile -> http://example.com/coolFolder/coolFile
string url3 = "http://example.com/" + "coolFolder/coolFile".Replace("/", "%252F");
var uwr3 = UnityWebRequest.GetAssetBundle(url3);
Debug.Log(url3 + " -> " + uwr3.url);
http://example.com/coolFolder%252FcoolFile -> http://example.com/coolFolder%252FcoolFile
Answer by elenzil · Oct 13, 2016 at 04:27 PM
send in the sad trombones.
two other long-shots come to mind:
modify the server to accept some other delimiter. This may not be an option of course.
the ugui system is available from unity as source: you can tweak it and recompile the .dll. perhaps UnityWebRequest is the same ?
report a bug. (free bonus suggestion!)