示例#1
0
        private IEnumerator SendPost()
        {
            WWWForm dataform = new WWWForm();

            MyClassForJSon post = new MyClassForJSon();

            FillTheFieldsOfEntity(post);

            string json = JsonUtility.ToJson(post);

            UnityWebRequest request = UnityWebRequest.Post(_url, dataform);

            byte[] postByte = Encoding.UTF8.GetBytes(json);

            UploadHandler uploadhandler = new UploadHandlerRaw(postByte);

            request.uploadHandler = uploadhandler;

            request.SetRequestHeader("Content-Type", "application/json; charset=UTF-8");

            yield return(request.SendWebRequest());

            MyClassForJSon postFromServer = JsonUtility.FromJson <MyClassForJSon>(request.downloadHandler.text);

            Debug.Log(postFromServer);
        }
示例#2
0
 private void Start()
 {
     _myEntity         = new MyClassForJSon();
     _path             = Application.streamingAssetsPath + "\\myEntity";
     _myEntity.myRank  = 0;
     _myEntity.myMoney = 0;
     _myEntity.myName  = "NoOne";
 }
示例#3
0
 private void FillTheFieldsOfEntity(MyClassForJSon post)
 {
     post.myName  = "Mikey";
     post.myMoney = 888888;
     post.myRank  = 0;
 }