Ejemplo n.º 1
0
        protected override void ParseBody(string data)
        {
            if (IsGzipEncoded())
            {
                data = TryDeflateDecoded(data);
            }
            // Some weired hash leading..
            var jsonString = Regex.Replace(data, @"\![a-z0-9]+$", "", RegexOptions.IgnoreCase);

            // In case of BOM of doom..
            jsonString = Regex.Replace(jsonString, "^", "");
            if (jsonString.Length == 0)
            {
                BodyJson   = null;
                BodyString = "";
                return;
            }

            // ... check for missing value..
            if (jsonString.Length > 0 && jsonString.Substring(jsonString.Length - 1, 1) == ":")
            {
                // Fix it with zero for now...
                jsonString += "0";
            }

            // Omfg.. seems like the removed the closing tags? Try to read it with a custom parser
            BodyJson   = JsonParser.Deserialize(jsonString);
            BodyString = BodyJson.ToString();
        }
Ejemplo n.º 2
0
 protected override void ParseBody(string jsonString)
 {
     try {
         BodyJson   = JsonParser.Deserialize(jsonString);
         BodyString = BodyJson.ToString();
     } catch {
         BodyJson   = null;
         BodyString = jsonString;
     }
 }
        public void ConfigurationServiceValidGetTest(Parameters parameter, Valid inputType)
        {
            var handler = new ConfigurationServiceManager();
            var request = new Dictionary <string, string>(DefaultParameters);

            request[parameter.ToString().ToLower()] = ValidGetMapping[inputType];
            request["body"] = BodyJson.Replace("db01", Utils.RandomString(20));

            //Create configuration service
            CreateConfigurationService(request["service"], request["id"], request["body"]);

            //Get and verify configuration service
            GetAndVerifyConfigurationService(request["service"], request["id"], request["body"]);
        }
        public void CreateAndThenUpdateConfigurationServiceTest()
        {
            var handler = new ConfigurationServiceManager();
            var request = new Dictionary <string, string>(DefaultParameters);

            request["body"]    = BodyJson.Replace("db01", Utils.RandomString(20));
            request["service"] = "create/update";

            //Create configuration service
            CreateConfigurationService(request["service"], request["id"], request["body"]);

            //Update configuration service with new body json
            request["body"] = BodyJson.Replace("db01", Utils.RandomString(20));
            CreateConfigurationService(request["service"], request["id"], request["body"]);

            //Get and verify configuration service
            GetAndVerifyConfigurationService(request["service"], request["id"], request["body"]);
        }
    //コルーチン
    IEnumerator OnSend(string url)
    {
        //URLをGETで用意
        UnityWebRequest webRequest = UnityWebRequest.Get(url);

        //レスポンスが戻ってくるまで待機
        yield return(webRequest.SendWebRequest());

        //エラーが出ていないかチェック
        if (webRequest.isNetworkError)
        {
            //通信失敗
            Debug.Log("Error!: " + webRequest.error);
        }
        else
        {
            //通信成功
            string dataStr = webRequest.downloadHandler.text;
            Debug.Log("Successed!: " + dataStr);

            BodyJson     bodyJson = JsonUtility.FromJson <BodyJson>(dataStr);
            List <float> x        = bodyJson.pca_data.x;
            List <float> y        = bodyJson.pca_data.y;
            List <float> z        = bodyJson.pca_data.z;

            string xStr = "";
            string yStr = "";
            string zStr = "";
            for (int i = 0; i < 3; i++)
            {
                xStr += x[i].ToString() + ", ";
                yStr += y[i].ToString() + ", ";
                zStr += z[i].ToString() + ", ";
            }
            Debug.Log("x = " + xStr);
            Debug.Log("y = " + yStr);
            Debug.Log("z = " + zStr);
        }
    }
Ejemplo n.º 6
0
    // https://blog.applibot.co.jp/2016/07/20/unity-webrequest/
    // 使用する際はurlを変更する。
    IEnumerator GetText()
    {
        UnityWebRequest request = UnityWebRequest.Get("https://u9o2yq1n5j.execute-api.ap-northeast-1.amazonaws.com/sample");

        // 下記でも可
        // UnityWebRequest request = new UnityWebRequest("http://example.com");
        // methodプロパティにメソッドを渡すことで任意のメソッドを利用できるようになった
        // request.method = UnityWebRequest.kHttpVerbGET;

        // リクエスト送信
        yield return(request.SendWebRequest());

        // 通信エラーチェック
        if (request.isNetworkError)
        {
            Debug.Log(request.error);
        }
        else
        {
            if (request.responseCode == 200)
            {
                //UTF8文字列として取得する
                text = request.downloadHandler.text;
                Debug.Log(text);
                BodyJson     bodyJson = JsonUtility.FromJson <BodyJson>(text);
                List <float> x        = bodyJson.pca_data.x;
                List <float> y        = bodyJson.pca_data.y;
                List <float> z        = bodyJson.pca_data.z;
                for (int i = 0; i < x.Count; i++)
                {
                    data.Add(new Vector3((float)x[i], (float)y[i], (float)z[i]));
                }
                Debug.Log(data[0]);
            }
        }
    }