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");

 

posted on 2018-11-05 16:59  &大飞  阅读(2653)  评论(0编辑  收藏  举报

导航