Question by
rueetschit · Oct 26, 2018 at 04:02 PM ·
jsonapiwebrequestpost
Issue with sending Json via UnityWebRequest
Hello!
I want to send a simple JSON string to the Google Perspective API via UnityWebRequest. Everything seems to be working fine, but there seems to be a problem with my string. I always get an error saying "Invalid JSON payload received. Unknown name \"{comment:{text:\"Test\"},requestedAttributes:{TOXICITY:{}}}\": Cannot bind query parameter. Field '{comment:{text:\"Test\"},requestedAttributes:{TOXICITY:{}}}' could not be found in request message.". Here's my code:
IEnumerator MakeCall(){
string url = "https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key=XXXXXXX";
string requestJson = "{comment:{text:\"Test\"},requestedAttributes:{TOXICITY:{}}}";
UnityWebRequest uwr = UnityWebRequest.Post(url, requestJson);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError)
{
Debug.Log("Error While Sending: " + uwr.error);
}
else
{
Debug.Log("Received: " + uwr.downloadHandler.text);
}
}
When I try to send the same string via curl command in terminal, it seems fine and I get my answer from the API. Can anybody tell me where the problem could be?
Thanks!
Comment