Unity3D通过UnityWebRequest方式使用Post方法

 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.SendWebRequest();

        Debug.Log("Status Code: " + request.responseCode);
      

        if (request.isHttpError || request.isNetworkError)
        {
            Debug.LogError(request.error);
            text.text = request.error;
        }
        else
        {
            Debug.Log(request.downloadHandler.text);
            text.text = request.downloadHandler.text;
        }
    }

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页