UnityWebRequest to send you post data on..." />
home, UNITY, updated

How to send POST data in c# unity?

You can use UnityWebRequest to send you post data on server with WWWForm.

Here is an sample code:


void Start()
{
    StartCoroutine(sendRequest("Your URL"));
}

IEnumerator sendRequest(string url)
{
    WWWForm form = new WWWForm();
    form.AddField("name", "xyz");
    form.AddField("age", "34");

    UnityWebRequest request = UnityWebRequest.Post(url, form);
    yield return request.SendWebRequest();

    if (request.isNetworkError)
    {
        Debug.Log("Error While Sending: " + request.error);
    }
    else
    {
        Debug.Log("Received: " + request.downloadHandler.text);
    }
}

Related Articles

post a comment