Get and Post(Unity3D六个发展)
2015-08-08 09:03
405 查看
猴子原创,欢迎转载。
转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢!
原文地址: http://www.cocos2dev.com/?p=565
unity3d中的www直接提供了web请求服务。使用也很easy。
转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢!
原文地址: http://www.cocos2dev.com/?p=565
unity3d中的www直接提供了web请求服务。使用也很easy。
using UnityEngine; using System.Collections.Generic; using System.Collections; public class WebManager : MonoBehaviour { // Use this for initialization void Start () { // Request by get StartCoroutine(Get("http://www.cocos2dev.com/")); // Request by post Dictionary<string, string> dic = new Dictionary<string, string> (); dic.Add("userId", "6001345679887"); dic.Add("eventId", "10018"); StartCoroutine(Post("http://192.168.1.102/api.php", dic)); } // Update is called once per frame void Update () { } // Post IEnumerator Post(string url, Dictionary<string, string>postData) { WWWForm form = new WWWForm(); foreach(KeyValuePair<string, string> postArg in postData) { form.AddField(postArg.Key, postArg.Value); } WWW www = new WWW(url, form); yield return www; if (www.error != null) { Debug.Log("error is :"+ www.error); } else { Debug.Log("request result :" + www.text); } } // Get IEnumerator Get(string url) { WWW www = new WWW (url); yield return www; if (www.error != null) { Debug.Log("error is :"+ www.error); } else { Debug.Log("request result :" + www.text); } } }
相关文章推荐
- unity代码反混淆
- unity 反编译 step2 dll -->reflector
- unity 反编译 step1 disUnity
- c#语言与unity3D
- Unity3D技术之优化图形性能绘制调用批处理浅析
- Unity (四)
- Unity3d 导入图像尺寸失真解决方案
- unity, get Canvas Scaler referenceResolution
- unity 使用 sqlite 数据库遇到的问题 unity android 使用sqlite
- UnityShader实例11:积雪材质
- 【Unity 3D】学习笔记29:游戏的例子——简单的小制作地图
- Unity中可用Lua版本效率分析比较
- Unity引擎在执行协程(Coroutine)的原理
- 关于unity shader的StencilBuffer
- unity, change parent and keep localPosition or worlPosition
- Unity取消默认打开上次工程
- unity, access sprite of UGUI Image
- unity, UGUI Text outline
- unity, sprite atlas
- Unity3D合并着色器