37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using BepInEx.Configuration;
|
|
using UnityEngine.Networking;
|
|
|
|
namespace Cult_of_the_Shock
|
|
{
|
|
public class Shocker
|
|
{
|
|
public void Shock(string json)
|
|
{
|
|
var uwr = new UnityWebRequest(Plugin.Config.GetURL() + "/1/shockers/control", "POST");
|
|
uwr.SetTimeoutMsec(1000);
|
|
|
|
uwr.SetRequestHeader("OpenShockToken", Plugin.Config.GetToken());
|
|
uwr.SetRequestHeader("Content-Type", "application/json");
|
|
|
|
byte[] requestData = new UTF8Encoding().GetBytes(json);
|
|
uwr.uploadHandler = new UploadHandlerRaw(requestData);
|
|
uwr.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
uwr.SendWebRequest();
|
|
while (!uwr.isDone)
|
|
{
|
|
Thread.Yield();
|
|
}
|
|
|
|
if (uwr.result != UnityWebRequest.Result.Success)
|
|
{
|
|
Plugin.Logger.LogError("Error while Sending Request: " + uwr.error);
|
|
Plugin.Logger.LogError(uwr.downloadHandler.text);
|
|
Plugin.Logger.LogError("Sent JSON: " + json);
|
|
}
|
|
}
|
|
}
|
|
}
|