using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExamInfoData
{
public string examId;
public string userId;
public string topicId;
public string score;
public ExamInfoData()
{
}
public ExamInfoData(string _examId, string _userId, string _topicId, string _score)
{
examId = _examId;
userId = _userId;
topicId = _topicId;
score = _score;
}
}
public void PostScore()
{
ExamInfoData band = new ExamInfoData(NewBehaviourScript.Instance.examId, NewBehaviourScript.Instance.userId, NewBehaviourScript.Instance.topicId, "10");
string json = JsonMapper.ToJson(band);
json = Regex.Unescape(json);
StartCoroutine(PostBodyData("https://......url......", json,
data =>
{
Debug.Log(data);
}));
}
public IEnumerator PostBodyData(string url, string bodyJsonString, System.Action<string> callback)
{
using (UnityWebRequest webRequest = new UnityWebRequest(url, "POST"))
{
byte[] bodyRaw = Encoding.UTF8.GetBytes(bodyJsonString);
webRequest.certificateHandler = new CertHandler();
webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
webRequest.SetRequestHeader("Content-Type", "application/json");
yield return webRequest.SendWebRequest();
if (webRequest.isHttpError || webRequest.isNetworkError)
{
Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text);
if (callback != null)
{
callback(null);
}
}
else
{
if (callback != null)
{
callback(webRequest.downloadHandler.text);
}
}
}
}