Unity adding an extra character to WWW.text

I have a database, where I have a table which contains URL’s.

I have a .php script that shows me the URL. If I run the script in the browser, then copy and paste the result string in the browser, the image loads sucessfully.

But, I’m trying to get this URL trough Unity, with the script:

go = WWW(url);
yield go;

var imageurl = go.text;

The problem is:

When I try to acces the URL later, with the given text, Unity doesn’t recognize the URL as http. If I do a print(imageurl), then copy and paste this URL from Unity to inside the browser, I am redirected to Google.

The string in Unity has 39 characters, but the original from the page has 38.

Unity is adding an extra character before the “http” in the string.

I tried replacing this character, but I need to replace with a null character which will be ignored before the “http”, I tried imageurl.Remove(0,0), but stills not working.

Ok, solved, I tried imageurl.Remove(0,1), but this is such a cheap trick, why Unity adds and extra character to the WWW.text?

1 Answer

1

Have you checked what the character is?

If this is a bug in Unity’s WWW class, it would be the first I’ve heard of it. Personally, I think it’s more likely that the problem is something much simpler. Are you entirely sure that your PHP isn’t echoing any extra characters? You might try grabbing the content with some other tool to see if it behaves as you expect.

The script reference mentions that WWW.text expects web content to be encoded in ASCII or UTF-8. It seems unlikely that you’d be using some other encoding, but it’s one more thing to check.