Hi All,
I am trying to connect to a Rest API which is in my localhost(WAMP) to insert data to a DB. I am using WWW for the same in C# script file. **When I am running it from my editor I am getting an error**: unable to connect to host. **But when I take a build and execute, the API is being called and the data is inserted into the DB**. Why am I not able to do that from the editor? Here is the code.
public void callApi()
{
string url = "http://localhost:8080/RestTest/index.php/Test/InsertTest/";
WWW w = new WWW(url);
StartCoroutine(WaitForRequest(w));
}
private IEnumerator WaitForRequest(WWW w)
{
yield return w;
yield return new WaitForSeconds(10f);
// check for errors
if (w.error == null)
{
Debug.Log("WWW Ok!: " + w.text);
}
else
{
Debug.Log("WWW Error: " + w.error);
}
}
CallAPI is called on a button click.
Please help me on this.
Thank You
↧