# UnityWWW **Repository Path**: withtimer/UnityWWW ## Basic Information - **Project Name**: UnityWWW - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-11-21 - **Last Updated**: 2021-03-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; public class NetW : MonoBehaviour { public string url = "http://super.weekcat.cn/static/img/exm2.b21424e.png"; public SpriteRenderer renderer3; public Text text; public Texture2D texture; public SpriteRenderer spriter; // Use this for initialization IEnumerator Start () { Debug.Log("OOK"); WWW www = new WWW(this.url); yield return www; this.renderer3.material.mainTexture = www.texture; // StartCoroutine("getData"); StartCoroutine("postData"); } // Update is called once per frame void Update () { } //get请求 IEnumerator getData() { string url = "http://super.weekcat.cn"; WWW www = new WWW(url); yield return www; if (www.error != null) { yield return null; } string t = www.text; this.text.text = t; } //post请求 IEnumerator postData() { string url = ""; System.Collections.Hashtable header = new System.Collections.Hashtable(); header.Add("Content-Type", "application/x-www-form-urlencoded");//哈希表的数据格式 string data = "username=post&password=67889"; byte[] bs = System.Text.UTF8Encoding.UTF8.GetBytes(data); WWW www = new WWW(url,bs,header); yield return www; string msg = ""; if (www.error != null) { msg = www.error; yield return null; } msg = www.text; this.text.text = msg; } //图片上传 IEnumerator uploadImg() { string url = ""; byte[] bs = this.texture.EncodeToPNG(); WWWForm form = new WWWForm(); form.AddBinaryData("picture", bs, "screenshot", "image/png"); WWW www = new WWW(url, form); yield return www; if (www.error != null) { string msg = www.error; yield return null; } this.texture = www.texture; } }