Get and Post(Unity3D六个发展)
and 发展 get post Unity3D 六个
2023-09-11 14:21:01 时间
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); } } }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
相关文章
- [Svelte 3] Use await block to wait for a promise and handle loading state in Svelte 3
- [Angular] In angular world and out angular world
- [Angular] Configurable Angular Components - Content Projection and Input Templates
- [Javascript] Prototype, hasOwnProperty(), valueOf() and toString() methods.
- backslash and newline separated by space
- metadata in OData and png
- Atitit.播放系统规划新版本 v4 q18 and 最近版本回顾
- Atitit.注解and属性解析(2)---------语法分析 生成AST attilax总结 java .net
- 【codeforces 791B】Bear and Friendship Condition
- (hdu step 6.3.2)Girls and Boys(比赛离开后几个人求不匹配,与邻接矩阵)