- Home /
Question by
tibby · May 19, 2014 at 01:21 PM ·
networkingwwwjson
how to find if WWW Post Request is succesful?
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);
Comment
Best Answer
Answer by Landern · May 19, 2014 at 01:29 PM
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.
Answer by tw1st3d · May 19, 2014 at 01:37 PM
yield return www;
if(!String.IsNullOrEmpty(www.error)) {
// If www.error is instantiated or has some string information in it, an error occurred.
}
Don't know why you changed my answer from www.error == null, because that works perfectly fine.