public static class UnityWebRequestExtension { /// <summary> /// Json を追加 /// </summary> public static void AddJson(this UnityEngine.Networking.UnityWebRequest self, string json) { var postData = System.Text.Encoding.UTF8.GetBytes(json); self.uploadHandler = new UploadHandlerRaw(postData); self.downloadHandler = new DownloadHandlerBuffer(); self.SetRequestHeader("Content-Type", "application/json"); } }
サンプル
var request = new UnityWebRequest("http://hoge", "POST"); // Json パラメータを Header に追加する request.AddJson(json);