using UnityEngine;
using System.Collections;
using System.Net;
using System.Text;
public class Test : MonoBehaviour
{
// Use this for initialization
void Start()
{
//StartCoroutine(GetWebData());
WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultCredentials;
byte[] pageData = myWebClient.DownloadData("http://www.baidu.com");
string pageHtml = Encoding.UTF8.GetString(pageData);
Debug.Log("pageHtml" + pageHtml);
}
IEnumerator GetWebData()
{
WWW www = new WWW("http://www.baidu.com");
yield return www;
if (www.isDone && www.error == null)
{
Debug.Log("WebData" + www.text);
}
}
// Update is called once per frame
void Update()
{
}
}
Unity3D获取web数据的两种方法
最新推荐文章于 2023-08-13 12:50:12 发布