Question by
domdev · Feb 22, 2019 at 06:34 AM ·
androidiosunityeditorwebrequest
UnityWebRequest.Post Returning Empty String
I'm pining a Rasa server through Ngrok and postman is working fine.. it was working in few test, but then like 3rd time test.. the return text will be empty any possible reason?
I'm using Unity 2018.0.3.f2 Windows 10
I'm building it for android and Ios (unity cloud build)
here my code in posting
IEnumerator PostRequest_(string url, string json)
{
Debug.Log(url);
var uwr = new UnityWebRequest(url, "POST");
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json);
uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend);
uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
uwr.SetRequestHeader("Content-Type", "application/json");
uwr.SetRequestHeader("Cache-Control", "no-cache");
uwr.SetRequestHeader("Pragma", "no-cache");
uwr.SetRequestHeader("Accept", "*/*");
uwr.SetRequestHeader("Accept-Encoding", "gzip, deflate");
yield return uwr.SendWebRequest();
if (uwr.isNetworkError)
{
Debug.Log("Error While Sending: " + uwr.error);
}
else
{
Debug.Log("Received: " + uwr.downloadHandler.text);
itemData = JsonMapper.ToObject(uwr.downloadHandler.text);
bool hasElement = false;
foreach (var element in itemData)
{
hasElement = true;
break;
}
if (hasElement){
TTSObj.OnInputText(itemData [0]["text"].ToString());
}else {
Debug.Log("Received: Empty");
}
}
Comment
Your answer
Follow this Question
Related Questions
How to play a 360 degree video with stereo mode in Unity 3D 0 Answers
Android HTTPS POST Request 0 Answers
ios memory is much higher than android memory. 0 Answers
Unity Services In-App Purchases: How to check if a user has bought a non-consumable product 4 Answers
Unity3d files convert to base64 encode 0 Answers