Unity自带WWW Get与Post的方式获得数据

来源:互联网 发布:php hashmap的实现原理 编辑:程序博客网 时间:2024/06/05 19:54



1.尝试GET方式通信

usingUnityEngine;usingSystem.Collections; publicclassJsonTest : MonoBehaviour {        privatestringurl  = "http://map.exceedu.com/iface/login.php?opt=logcheck";         // Use this for initialization        IEnumerator Start () {                WWW getData = newWWW(url);                yieldreturngetData;                if(getData.error != null) {                          Debug.Log(getData.error);                 }                 else{                         Debug.Log(getData.text);                 }                 }}


2.利用POST方式通信

usingUnityEngine;usingSystem.Collections; publicclassJsonTest : MonoBehaviour {        privatestringurl  = "http://map.exceedu.com/iface/login.php?opt=logcheck";         // Use this for initialization        IEnumerator Start () {                WWWForm form  = newWWWForm();                form.AddField("userid","ABC");                form.AddField("pwd","***");                WWW getData = newWWW(url, form);                yieldreturngetData;                if(getData.error != null) {                          Debug.Log(getData.error);                 }                 else{                         Debug.Log(getData.text);                 }                 }}










1 0
原创粉丝点击