Skip to content

Instantly share code, notes, and snippets.

@junaid109
Created October 3, 2022 10:41
Show Gist options
  • Save junaid109/7489a85d1ffb3177ff7e984c1bd2eed5 to your computer and use it in GitHub Desktop.
Save junaid109/7489a85d1ffb3177ff7e984c1bd2eed5 to your computer and use it in GitHub Desktop.
Post method in unity
private IEnumerator PostRegistrationDetails(string jsonData)
{
var raw = Encoding.UTF8.GetBytes(jsonData);
using UnityWebRequest webRequest = UnityWebRequest.Post(uriPostResults, "POST");
webRequest.SetRequestHeader("Content-Type", "application/json");
webRequest.uploadHandler = new UploadHandlerRaw(raw);
webRequest.uploadHandler.contentType = "application/json";
webRequest.downloadHandler = new DownloadHandlerBuffer();
webRequest.SendWebRequest();
if (webRequest.isNetworkError || webRequest.isHttpError)
{
Debug.Log("Error: " + webRequest.error);
}
else
{
Debug.Log("Success");
}
yield return new WaitForSeconds(1f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment