Hello guys,
Im trying to do a get Request to a server using Unity web request but im getting a “Cannot connect to destination host” error.
The URL is working in a browser but it simply fails everytime from unity. The URL that im trying to get is classified by the browser as not secure so Im not sure if this could cause this error.
IEnumerator descargarListaServidores(){
UnityWebRequest www = UnityWebRequest.Get("xxx.xxx.xxx.xxx:14100/infoServidor");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success) {
Debug.Log(www.error);
}else {
textoListaDeServidores = www.downloadHandler.text;
Debug.Log(textoListaDeServidores);
}
yield return null;
}
Networking, UnityWebRequest, WWW, Postman, curl, WebAPI, etc:
As with all network code, get it working with Postman or curl first. That makes it NOT a Unity problem. Solve the networking first. You must solve that or anything else is irrelevant.
Once you have that working, then try and port it to UnityWebRequest. If it still doesn't work, one handy debug solution is to hook up a proxy like Charles and compare the functioning output from Postman / curl to the output from Unity, and from that reason about where your issues are.
Always get network stuff working outside of Unity in either curl or PostMan, then connect a proxy such as Charles and start trying to replicate the traffic shape with UnityWebRequest.
Any other way risks wasting a lot of your time for trivial issues that only the above way will instantly reveal.
And setting up a proxy can be very helpful too, in order to compare traffic:
If thos ‘x’ characters are the IP address, then your URL is missing the http:// prefix.
1 Like