tibby
May 19, 2014, 1:21pm
1
How do I know if my post request has been received by the server or if the server is accessible?
string ourPostData = "{\"Name\": \"Jack\", \"Score\":3455, \"Character\": \"Bob\" }";
Hashtable headers = new Hashtable();
headers.Add("Content-Type", "application/json");
headers.Add("Cookie", "Our session cookie");
byte[] pData = Encoding.ASCII.GetBytes(ourPostData.ToCharArray());
WWW www = new WWW("http://localhost:8082/test", pData, headers);
yield the www variable, when it’s complete and a response is ready to go, the code will continue after the yield statement.
First example of the WWW.WWW from Unity docs .
From the docs:
After the stream is created you have to wait for it to complete, then you can access the downloaded data. As a convenience the stream can be yielded, so you can very easily tell Unity to wait for the download to complete.
yield return www;
if(!String.IsNullOrEmpty(www.error)) {
// If www.error is instantiated or has some string information in it, an error occurred.
}