using Newtonsoft.Json;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class HttpController : MonoBehaviour
{
public static string URL = "http://localhost:3000/";
public static IEnumerator Post(string item1, string content1)
{
WWWForm formData = new WWWForm();
formData.AddField(item1, content1);
using (UnityWebRequest request = UnityWebRequest.Post(URL, formData)) // эта суета делается для Dispose();
{
request.SetRequestHeader("User-Agent", "UnityApp");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ProtocolError | request.result == UnityWebRequest.Result.ConnectionError)
{
Debug.Log(request.result);
}
else
{
var answer = JsonConvert.DeserializeObject<WebResponse>(request.downloadHandler.text);
Debug.Log("получилось" + answer);
}
}
}
}