Unity 中使用WWW类 请求服务器数据

可以简单的搭建个服务器先调通
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Http : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
		StartCoroutine("RequestServer");
	}


	public IEnumerator RequestServer()
	{
		string url = "http://127.0.0.1:8888";
		WWW www = new WWW (url);
		yield return www;
		if (string.IsNullOrEmpty (www.error)) {
			string resultData = www.text;
			Debug.Log (resultData);
		}else{
			Debug.Log (www.error);
		}
	}
}

你可能感兴趣的:(Unity)