- Home /
UnityWebRequest POST JSON FAIL
1) the POST success on POSTMAN
2) the Code is:
UnityWebRequest www = new UnityWebRequest(url, "POST"); www.chunkedTransfer = false; byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonAvance); www.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); www.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); www.SetRequestHeader("Content-Type", "application/json"); yield return www.SendWebRequest(); if (www.isDone) { string jsonResult = www.downloadHandler.text;
3) When fail www.downloadHandler.text is ;
Invalid Request error was encountered while trying to process the request:
POST /wsmartenautas/index.php/subir-avance HTTP/1.0 Host: ... User-Agent: UnityPlayer/2017.4.8f1 (UnityWebRequest/1.0, libcurl/7.51.0-DEV) Accept: / Accept-Encoding: identity Content-Type: application/json X-Unity-Version: 2017.4.8f1 Content-Length: 1063 Expect: 100-continue Proxy-Connection: Keep-Alive
Some possible problems are: Missing or unknown request method. Missing URL. Missing HTTP Identifier (HTTP/1.0). Request is too large. Content-Length missing for POST or PUT requests. Illegal character in hostname; underscores are not allowed. HTTP/1.1 Expect: feature is being asked from an HTTP/1.0 software.
4) Note the use of HTTP1.0 in POST /wsmartenautas/index.php/subir-avance HTTP/1.0... i don know why unity use HTTP/1.0 must be HTTP/1.1