WWW class

Hello,

I made those functions that call a php file and return data,
but i’m unable to make the script wait for the request to end.

So is there a way to make a www request without Coroutine or yield it ?
Can we make a function in Csharp that make a www request and return the result (best: available using static call :p) ?

Thanks.

	public IEnumerator MakeRequest(string HandlerFile ,Hashtable RequestParams)
	{
		WWWForm RequestForm = new WWWForm();
		
		Crypt NewCrypt = new Crypt(key,iv);
		
		foreach(DictionaryEntry Param in RequestParams)
		{
			RequestForm.AddField( Param.Key.ToString(),  NewCrypt.Encrypt(Param.Value.ToString()) );
		}
		
		WWW w = new WWW(CoreUrl + HandlerFile, RequestForm);
		yield return w;
		
		if (w.error != null)
			{ RequestedData = null; Debug.Log(w.error); }
		else
		{
			RequestedData = NewCrypt.Decrypt(w.text);
			w.Dispose();
		}
	}
	
	
	public string Request(string Handler ,Hashtable RequestParams)
	{
		if(CoreHandlers.ContainsKey(Handler))
		{
			yield StartCoroutine(MakeRequest(CoreHandlers[Handler], RequestParams));
			return RequestedData;
		}
		else
		{
			print("Error : Unknown Handler");
			return null;
		}
	}

For sure, just store the WWW instance to your class and check it on the Update event:

public class MyClass
{
	private WWW Loader;
	
	
	private void Start()
	{
		Loader = new WWW("url");
	}
	
	private void Update()
	{
		if (Loader != null  Loader.isDone)
		{
			//do stuff
			
			Loader = null;
		}
	}
}

Just wrote that in notepad so it’s probably not fully correct, but you should get the idea.

I see, it works great but i found an other way with coroutines and callback for my main class.
However i keep your method in mind for something else in my project.

Thanks a lot.

Could you please share the code with coroutines and callback, thank you