I'm trying to combine a url and string at runtime and then call it.
public static Uri Append(this Uri uri, params string[] paths)
{
return new Uri(paths.Aggregate(uri.AbsoluteUri, (current, path) => string.Format("{0}/{1}", current.TrimEnd('/'), path.TrimStart('/'))));
}
var url = new Uri("https://127.0.0.1:2999/liveclientdata/playerscores?summonerName=").Append(_PlayerName).AbsoluteUri;
However when I call it, this error is returned:
Failed the request: HTTP/1.1 400 Bad Request
The url looks like this
https://127.0.0.1:2999/liveclientdata/playerscores?summonerName=/%22KidKiwi91%22
I know the error is caused by the concatenation of the url and string because it I make it all one url and not combine them in runtime it works.
Other things i've tried:
string url = "urlgoeshere=" + playername;
string url = UnityWebRequest.EscapeURL("urlgoeshere" + playername);
string url_q = "urlgoeshere=" + playername;
var url=new Uri(url_q);
It's called using this
private IEnumerator GetJSON(string url, System.Action<string> callback)
{
failed = false;
//Debug.Log(url);
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
webRequest.certificateHandler = new BypassCertificate();
yield return webRequest.SendWebRequest();
string error = webRequest.error;
if (error != null)
{
Debug.Log("Failed the request: " + error);
failed = true;
}
else
{
callback?.Invoke(webRequest.downloadHandler.text);
//Debug.Log(webRequest.downloadHandler.text);
}
}
}
Any ideas?
Thanks