I want to call a login api in unity 3d with two json parameter username and password.
I followed many post available on stackoverflow. But my request parameters are
You need to manually set the content header and the body of the message, and convert your form data string to a json string and send how parameter to CallLogin:
public IEnumerator CallLogin(string url, string logindataJsonString)
{
var request = new UnityWebRequest (url, "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(logindataJsonString);
request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();
if (www.error != null)
{
Debug.Log("Erro: " + www.error);
}
else
{
Debug.Log("All OK");
Debug.Log("Status Code: " + request.responseCode);
}
}