Exemple #1
0
    /// <summary>
    /// POST请求(Form表单传值、效率低、安全 ,)  
    /// </summary>
    /// <param name="url"></param>
    /// <param name="post"></param>
    /// <returns></returns>
    IEnumerator POST(string url, Dictionary<string, string> post, NetClientCallBackInterface ncbi)
    {
        ///< 网络不可用
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            ncbi.onNet("网络不可用!");
        }
        else
        {
            ///< 表单   
            WWWForm form = new WWWForm();
            ///< 从集合中取出所有参数,设置表单参数(AddField()).  
            foreach (KeyValuePair<string, string> post_arg in post)
            {
                form.AddField(post_arg.Key, post_arg.Value);
            }
            ///< 表单传值,就是post   
            WWW www = new WWW(url, form);

            yield return www;

            if (www.error != null)
            {
                ///< POST请求失败  
                ncbi.onFailer("error:" + www.error);
            }
            else
            {
                ///< POST请求成功  
                ncbi.onSucces(StatusCode.NETSTATE.STRING_RESPONSE, www.text);
            }
        }
    }  
Exemple #2
0
    /// <summary>
    /// GET请求_获取存档信息(url?传值、效率高、不安全 ) 
    /// </summary>
    /// <param name="url"></param>
    /// <param name="get"></param>
    /// <param name="ncbi"></param>
    /// <returns></returns>
    public static IEnumerator GET_ArchiveInf(Dictionary<string, string> get, NetClientCallBackInterface ncbi)
    {
        ///< 网络不可用
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            ncbi.onNet("网络不可用!");
        }
        else
        {
            string parameters;
            bool first;
            if (get.Count > 0)
            {
                first = true;
                parameters = "?";
                ///< 从集合中取出所有参数,设置表单参数(AddField()). 
                foreach (KeyValuePair<string, string> post_arg in get)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        parameters += "&";
                    }

                    parameters += post_arg.Key + "=" + post_arg.Value;
                }
            }
            else
            {
                parameters = "";
            }

            ///< 直接URL传值就是get 
            WWW www = new WWW(requestArchiveInf_URL + parameters);
            yield return www;

            if (null != www.error)
            {
                ///< GET请求失败  
                ncbi.onFailer("error:" + www.error);
            }
            else
            {
                ///< GET请求成功  
                ncbi.onSucces(StatusCode.NETSTATE.STRING_RESPONSE, www.text);
            }
        }
    }
Exemple #3
0
    /// <summary>
    /// GET请求_获取图片(url?传值、效率高、不安全 ) 
    /// </summary>
    /// <param name="url"></param>
    /// <param name="get"></param>
    /// <param name="ncbi"></param>
    /// <returns></returns>
    public static IEnumerator GET_Pic(string picURL, NetClientCallBackInterface ncbi)
    {
        ///< 网络不可用
        if (picURL.Contains("http://") && Application.internetReachability == NetworkReachability.NotReachable)
        {
            ncbi.onNet("网络不可用!");
        }
        else
        {
            ///< 直接URL传值就是get 
            WWW www = new WWW(picURL);
            yield return www;

            if (null != www.error)
            {
                ///< GET请求失败  
                ncbi.onFailer("error:" + www.error);
            }
            else
            {
                ///< GET请求成功  
                ncbi.onSucces(StatusCode.NETSTATE.TEXTURE_RESPONSE, www.texture);
            }
        }
    }