Unity Http PostリクエストのJSONパラメータ

Litjsonの使用

    void Start()
    { 
        // litJsonを使用してjson形式のパラメーターデータを作成する 
        JsonData data = new JsonData(); 
        data [ " バックエンドとネゴシエートされたパラメーター名" ] = " 書き込みたいパラメーター" ;
         バイト [] postBytes = System.Text.Encoding.Default.GetBytes(data.ToJson()); 

        // ネイティブUnityWebRequestを使用(推奨) 
        StartCoroutine(UnityWebRequestPost(" Your url " 、postBytes)); 

        // UniRx 
        ObservableWWW.Post(" You URL "、postBytes、新しいディクショナリ< 文字列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)新しいDownloadHandlerBuffer(); 
        request.SetRequestHeader(" Content-Type "" application / json " );
        返品リクエストを生成し ます。SendWebRequest(); 
        Debug.Log(" ステータスコード:" + request.responseCode);
        if(request.isNetworkError || request.isHttpError)
        { 
            Debug.LogError(request.error); 
        } else 
        { 
            Debug.Log(request.downloadHandler.text); 
        } 
    }
        

 

おすすめ

転載: www.cnblogs.com/unity3ds/p/12680239.html