How can resolve URL with caracter like & and other ?

Hello everybody

I’m trying to make a script to read Json File. But in the URL, I’ve got symbol like “&” and “=”.

http://192.168.151.140/nagios/cgi-bin/statusjson.cgi?query=host&hostname=Client_Windows_01

But when i try to load the page content, the path is wrong. I think is truncated. I’ve got this:

http://192.168.151.140/nagios/cgi-bin/statusjson.cgi

So I’ve got explored another solution. It concist to trucate the url string in two part and use EscapeURL function.
See bellow my part of code. But it doesn’t work.

Code (CSharp):

private string pathSample1 = "http://192.168.151.140/nagios/cgi-bin/statusjson.cgi?query=host&hostname=Client_Windows_01";
 
string url="http://192.168.151.140/nagios/cgi-bin/statusjson.cgi";
string url2="?query=host&hostname=Client_Windows_01";
 
private IEnumerator DownloadJsonFile(string url) {
        jsonString = null;
        yield return StartCoroutine(DownloadFile(url, fileContents => jsonString = fileContents));
        jsonLogString = TruncateStringForEditor(jsonString);
    }
 
    private string TruncateStringForEditor(string str) {
        if(str.Length>4096) str = str.Substring(0,4000)+"

… display truncated …
";
return str;
}

    private IEnumerator DownloadFile(string url, System.Action<string> result) {
        WWWForm form = new WWWForm();
        form.AddField("dummy", "field");
   
        WWW www = new WWW(url + WWW.EscapeURL(url2), form.data, new System.Collections.Generic.Dictionary<string,string>() {
            {"Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(username+":"+password))}
        });
        yield return www;
        result(www.text);
    }

;

can you help me ?
(sorry for ma bad english…)

Kind regards and thank you in advance

Hello Doublemax,

Great, it work :slight_smile: Thank you for your Help.

Kind regards

Try something like this:

WWWForm form = new WWWForm();
form.AddField("query", "host");
form.AddField("hostname", "Client_Windows_01");

WWW www = new WWW( "http://192.168.151.140/nagios/cgi-bin/statusjson.cgi", form );