unitywebrequest-post-url-jsondata


IEnumerator Post(string url, string bodyJsonString)
    {
        var request = new UnityWebRequest(url, "POST");
        byte[] bodyRaw = Encoding.UTF8.GetBytes(bodyJsonString);
        request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
        request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
 
        yield return request.Send();
 
        Debug.Log("Status Code: " + request.responseCode);
    }

 

Oddly Unity has two different ways? I found that this version they supply works?

https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Post.html

Yes, there are two ways:
UnityWebRequest.Post(url, form);
and
new UnityWebRequest(url, "POST");

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM