首页 > 编程语言 > 详细

unity 里的get和post方法调用

时间:2016-06-15 18:49:28      阅读:379      评论:0      收藏:0      [点我收藏+]

(一)GET方法

 

IEnumerator SendGet(string _url)
    {
        WWW getData = new WWW(_url);
        yield return getData;
        if(getData.error != null)
        {
            Debug.Log(getData.error);
         }
        else
        {
             Debug.Log(getData.text);
         }
    }


(二)POST方法

IEnumerator SendPost(string _url, WWWForm _wForm)
    {
        WWW postData = new WWW(_url, _wForm);
        yield return postData;
        if (postData.error != null)
        {
            Debug.Log(postData.error);
        }
        else
        {
            Debug.Log(postData.text);
        }
    }


调用两个方法

public void TestHttpSend()
    {
        //测试GET方法
        StartCoroutine(SendGet("http://kun.show.ghostry.cn/?int=5"));

        //测试POST方法
        WWWForm form = new WWWForm();
        form.AddField("int", "6");
        StartCoroutine(SendPost("http://kun.show.ghostry.cn/", form));     
    }

unity 里的get和post方法调用

原文:http://www.cnblogs.com/ZeroMurder/p/5588312.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!