From 65d52c31fbd11a475834fb203d1bc258178afdb8 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Thu, 21 Sep 2017 00:51:23 +0900 Subject: [PATCH] Fix HFTSite for Unity 2017 Unity broke the WWW class so I had to switch to UnityWebRequest --- .../HappyFunTimesCore/Server/HFTSite.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Assets/HappyFunTimes/HappyFunTimesCore/Server/HFTSite.cs b/Assets/HappyFunTimes/HappyFunTimesCore/Server/HFTSite.cs index 9069582..b0bb693 100644 --- a/Assets/HappyFunTimes/HappyFunTimesCore/Server/HFTSite.cs +++ b/Assets/HappyFunTimes/HappyFunTimesCore/Server/HFTSite.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Net; using UnityEngine; +using UnityEngine.Networking; namespace HappyFunTimes { @@ -39,7 +40,7 @@ class Informer { int tryCount_ = 0; bool done_ = false; bool haveNewAddresses_ = false; - WWW www_; + UnityWebRequest www_; HFTLog log_; public Informer(HFTLog log, SharedState sharedState, string url, string domain) @@ -85,20 +86,19 @@ public void Stop(MonoBehaviour monoBehaviour) IEnumerator InformCoroutine() { - var headers = new Dictionary(); - headers["Content-Type"] = "application/json"; - headers["Host"] = domain_; + www_ = new UnityWebRequest(url_, UnityWebRequest.kHttpVerbPOST); + www_.uploadHandler = new UploadHandlerRaw(addressesBytes_); + www_.uploadHandler.contentType = "application/json"; + www_.downloadHandler = new DownloadHandlerBuffer(); - www_ = new WWW(url_, addressesBytes_, headers); + yield return www_.Send(); - yield return www_; - - string err = www_.error; - string result = www_.text; + bool isError = (www_.isNetworkError || www_.isHttpError); + string result = www_.downloadHandler.text; www_ = null; // Was it successful? - if (String.IsNullOrEmpty(err)) + if (!isError) { // Yes log_.Info("registered: " + addressesStr_ + " with " + domain_ + " for: " + result); @@ -230,7 +230,6 @@ IEnumerator CheckAddresses() oldAddressesStr_ = newAddressesStr; var data = new InformData(addresses, options_.port); var json = Serializer.Serialize(data); - log_.Info("sending: " + json); addressBytes_ = System.Text.Encoding.UTF8.GetBytes(json); haveNewAddresses = true; }