WWW ""cannot connect to destination host""

hi all,

this is for a chistmas present so it’s kinda pressing…

I just want to read text from an url. html or json and always get “cannot connect to destination host”, tried this on multiple devices with firewall off. If I would get a connection I could acces the data via www.text right?
everyone on the web seems to do it that way, but it won’t work here
I am going crazy…

using UnityEngine;
using System.Collections;

public class ExampleScript : MonoBehaviour
{
    public string url = "http%3A%2F%2Fwww.brainjar.com%2Fjava%2Fhost%2Ftest.html";
    IEnumerator Start()
    {
        using (WWW www = new WWW(url))
        {
            yield return www;
            if (!string.IsNullOrEmpty(www.error))
                Debug.Log(www.error);
        }
    }
}

added code tags, thx for link

Please read this page for how to post code properly on the forums :slight_smile:

Are you sure the url has to be written that way?
Have you ever tried something like: public string url = “http://google.com”;

Is it just this site that’s not working for you, or you can’t get it to work at all?

1 Like

Unity API says the urls have to be “% escaped” - If I use a normal url like Test HTML File it won’t even try to connect and I get no error message.

And yeah my code won’t work with other urls.

Yes, I saw that comment on the doc page, but I think that refers only to special characters. For instance, if you look at the ‘escapeURL’ and ‘unescapeURL’ methods, they show an example … something like “Fish & Chips” and how it gets converted to something like “Fish+%38+Chips” (forget the exact hex value).

When you say won’t even try to connect, just curious how do you know? From your code there is no way to tell ? (well, if you get no error).

Not true and you misunderstood what the escaping means.
The URL you pasted here is completely valid and would work!
The part about %-escaping applies to characters that are not part of URI syntax like spaces. The slashes that are part of URL syntax should remain slashes.

1 Like

Yeah, don’t escape all the slashes, there is no need. And you can always pass your link to Unity - Scripting API: WWW.EscapeURL to let it convert for you. But just use the link straight up, you’ll be fine.

no clue why but now it works with standard urls
thx guys

Cool glad you got it fixed/working :slight_smile: