예제 #1
0
	    // POST请求 - json
	    IEnumerator POST(string url, Dictionary<string, string> post, Fn callback)
	    {
	        WWWForm form = new WWWForm();
	        foreach (KeyValuePair<string, string> post_arg in post)
	        {
	            form.AddField(post_arg.Key, post_arg.Value);
	        }

	        WWW www = new WWW(url, form);
	        yield return www;

	        if (www.error != null)
	        {
	            //POST请求失败
	            Debug.Log("error is :" + www.error);
	        }
	        else
	        {
	            //POST请求成功
	            JSONNode obj = JSON.Parse(www.text);
				JSONClass args = obj.AsObject;
				if (args == null || !args.hasKey( "querySuccess" ))
				{
					Debug.LogError("Network Error: Http Response is not Json!" + www.text);
					yield break;
				}
				int querySuccess = args["querySuccess"].AsInt;
	            if (querySuccess == 1) //successs
	            {
	                callback(args);
	            }
	            else
	            {
	                int code = System.Int32.Parse(args["code"].ToString());
	                Debug.LogError(code);
	            }
	        }
	    }