using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking; using LitJson; public class testDemo : MonoBehaviour { public Text ttime; public Text tfct; public Text tfzct; public Text tjzct; // Start is called before the first frame update void Start() { ttime.text = DateTime.Now.ToString(); sendtest(); } public void load() { } public void sendtest() { StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle/total", new Dictionary(), (string msg) => { JsonData data = JsonMapper.ToObject(msg); int ct = int.Parse(data["data"]["list"]["001"].ToString())%14; Debug.Log("msg===>" + msg); int i = ct % 7; tfct.text = i+"/7"; tfzct.text = (ct / 7).ToString(); tjzct.text = "2"; Invoke("sendtest",1f); })); } public IEnumerator SendHttp(string methodName, Dictionary fromDic, Action CallBack) { Debug.Log("Start Queue SendHttp " + methodName); string url = "https://api-fat2.ghz-tech.com/" + methodName; UnityWebRequest webRequest; WWWForm form = new WWWForm(); foreach (var item in fromDic) { form.AddField(item.Key, item.Value); } webRequest = UnityWebRequest.PostWwwForm(url, "Post"); webRequest.SetRequestHeader("Content-Type", "application/json"); webRequest.SetRequestHeader("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjMxNTM2MDAxNzEyNzQ0NjUxLCJpYXQiOjE3MTI3NDQ2NTEsInVzZXIiOnsiaWQiOjExLCJlbWFpbCI6IiIsInBob25lIjoieWIzIiwibmFtZSI6InliMyIsInJvbGVJZCI6M319.WGpVJHfbTr4Bp2cySjjlgCIon8nF4sJxkl58wcIion8"); yield return webRequest.SendWebRequest(); if (webRequest.result == UnityWebRequest.Result.ConnectionError) { Debug.LogError(webRequest.error); } else { string result = webRequest.downloadHandler.text; CallBack(result); } } // Update is called once per frame void Update() { } }