中文字幕无码a片久久,亚洲日韩在线观看浪潮,人人超人人超碰超国产二区,国产人妻久久一区二区,国产人妻久久一区二区

福感科技有限公司 歡迎您!
聯(lián)系方式

    地址:北京市平谷區(qū)馬坊鎮(zhèn)金河北街17號院3號樓7層712

    電話:010-89968230

    網(wǎng)站:http://0743119.com

Unity Http Post請求之Json參數(shù)

2021-4-26 10:12:08??????點(diǎn)擊:

使用Litjson

void Start()
    {
        //使用litJson創(chuàng)建json格式的參數(shù)數(shù)據(jù)
        JsonData data = new JsonData();
        data["與后端協(xié)商好的參數(shù)名"] = "你要寫入的參數(shù)";
        byte[] postBytes = System.Text.Encoding.Default.GetBytes(data.ToJson());


        //使用原生UnityWebRequest(推薦)
        StartCoroutine(UnityWebRequestPost("你的url", postBytes));


        //使用UniRx
        ObservableWWW.Post("你的url", postBytes, new Dictionary<string, string>() { { "Content-Type", "application/json" } })
                     .Subscribe(result => Debug.Log(result));
    }


    IEnumerator UnityWebRequestPost(string url, byte[] postBytes)
    {
        UnityWebRequest request = new UnityWebRequest(url, "POST");


        request.uploadHandler = (UploadHandler)new UploadHandlerRaw(postBytes);
        request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
        yield return request.SendWebRequest();
        Debug.Log("Status Code: " + request.responseCode);
        if (request.isNetworkError || request.isHttpError)
        {
            Debug.LogError(request.error);
        }
        else
        {
            Debug.Log(request.downloadHandler.text);
        }
    }
聲明:文章內(nèi)容整理來源于網(wǎng)絡(luò),版權(quán)屬于原作者,如有問題,請聯(lián)系我們!

來源:https://www.cnblogs.com/unity3ds/p/12680239.html

Copyright 2019 0743119.com

福感科技有限公司 版權(quán)所有 All Rights Reserved

京ICP備20002031號

010-89968230