注释
简单的http通讯信息,可以适应简单的场景
void Start(){StartCoroutine(GetRequest("https://jsonplaceholder.typicode.com/posts/1"));StartCoroutine(PostRequest("https://jsonplaceholder.typicode.com","hahah"));}/// <summary>/// 获取网页上的信息/// </summary>/// <param name="uri"></param>/// <returns></returns>IEnumerator GetRequest(string uri){using (UnityWebRequest webRequest = UnityWebRequest.Get(uri)){yield return webRequest.SendWebRequest();if (webRequest.result == UnityWebRequest.Result.Success){Debug.Log("Received: " + webRequest.downloadHandler.text);}else{Debug.Log("Error: " + webRequest.error);}}}/// <summary>/// 发送信息到网页/// </summary>/// <param name="uri"></param>/// <param name="data"></param>/// <returns></returns>IEnumerator PostRequest(string uri, string data){List<IMultipartFormSection> formData = new List<IMultipartFormSection>();formData.Add(new MultipartFormDataSection("field1=foo&field2=bar"));UnityWebRequest www = UnityWebRequest.Post(uri, formData);yield return www.SendWebRequest();if (www.result == UnityWebRequest.Result.Success){Debug.Log("Post request successful!");}else{Debug.Log("Error: " + www.error);}}