Unity3D获取web数据的两种方法

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()
    {

    }
}

你可能感兴趣的:(Web,数据,unity3d)