public IEnumerator Get(EOPERATION op, string name) { string url = GetUrl(op, name); if (!string.IsNullOrEmpty(url)) { using (request = UnityWebRequest.Get(url)) { isStart = true; //设置超时 链接超时返回 且isNetworkError为true request.timeout = 30; yield return(request.SendWebRequest()); isStart = false; //结果回传给具体实现 if (request.isHttpError || request.isNetworkError) { Debug.Log(request.error); } else { _handers[op](new TokenMsg { name = name, hander = request.downloadHandler }); } }; } }
public IEnumerator Post(EOPERATION op, Dictionary <string, string> dic) { string url = GetUrl(op); if (!string.IsNullOrEmpty(url)) { WWWForm form = new WWWForm(); foreach (var item in dic) { form.AddField(item.Key, item.Value); } using (request = UnityWebRequest.Post(url, form)) { isStart = true; request.timeout = 30; yield return(request.SendWebRequest()); isStart = false; //结果回传给具体实现 if (request.isHttpError || request.isNetworkError) { Debug.Log(request.error); } else { _handers[op](new TokenMsg { hander = request.downloadHandler }); } } } }
string GetUrl(EOPERATION op, string name = "") { return(webWorkData.ipAddress + webWorkData.urlPaths[op] + name); }