zoukankan      html  css  js  c++  java
  • 一个简单的Post Get请求

    WWW请求

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Networking;
    
    public class WWWWebRequest : MonoBehaviour
    {
        enum WebRequestType
        {
            GET,
            POST_FORM,
            POST_URLENCONDING,
            POST_JSON,
            POST_XML
        }
    
        public static WWWWebRequest Instance;
    
        public void Get(string url,Action<WWW> actionGet)
        {
            StartCoroutine(Request(url,null, actionGet,WebRequestType.GET));
        }
    
        public void PostForm(string url, WWWForm form, Action<WWW> actionPost)
        {
            StartCoroutine(Request(url, form, actionPost, WebRequestType.POST_FORM));
        }
    
        IEnumerator Request(string url,WWWForm form,Action<WWW> action,WebRequestType type)
        {
            WWW www =  null;
    
            switch (type)
            {
                case WebRequestType.GET:
                    www = new WWW(url);
                    break;
                case WebRequestType.POST_FORM:   
                    www = new WWW(url, form);  
                    break;
                default:
                    break;
            }
    
            if(www==null)
            {
                Debug.Log("Cant config request paramater");
                yield break;
            }
    
            yield return www;
    
            action?.Invoke(www);
    
            www.Dispose();
            www = null;
            Resources.UnloadUnusedAssets();
        }
    
        private void Awake()
        {
            Instance = this;
        }
    }
  • 相关阅读:
    # 类和模板小结
    # Clion复制提示信息
    # IDEA相关知识
    # MySQL 笔记
    # MATLAB笔记
    # Mac地址
    # 丢包&&掉帧&&文件删除
    HDU 5744 Keep On Movin
    POJ 1852 Ants
    HDU 2795 Billboard
  • 原文地址:https://www.cnblogs.com/llstart-new0201/p/9728285.html
Copyright © 2011-2022 走看看