unity中使用www方式与web服务器进行数据请求,添加代码,将其挂载在main camera
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GetObj : MonoBehaviour
{
public InputField nameInput;
public InputField addressInput;
public void OnBtnLogin()
{
string name = null;
name = nameInput.text;
string address = null;
address = addressInput.text;
StartCoroutine(Request(name,address));
}
IEnumerator Request(string name,string address)
{
string url = "www.text.com/Handler1.ashx?name=" + name + "&address" + address;
WWW www = new WWW(url);
yield return www;
while (!www.isDone)
{
yield return new WaitForEndOfFrame();
}
if (www.error==null)
{
//打印出get请求回应内容
Debug.Log(www.text);
}
}
}
在unity中简单建如下图UI:
当点击按钮后,将打印出结果转载于感谢原作者:https://blog.csdn.net/qq_33747722/article/details/54295863
网友评论