Unity3d向web服务器发送数据
来源:互联网 发布:linux mysql命令 编辑:程序博客网 时间:2024/06/03 13:40
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;using System.Text;namespace UpdatePhoto{ public partial class UpdatePhoto : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string id = Request.Form["id"]; HttpPostedFile hfc = Request.Files["Photo"]; if (hfc == null) return; Stream sm = hfc.InputStream; byte[] buffer = new byte[sm.Length]; sm.Read(buffer, 0, buffer.Length); sm.Close(); string path = Request.PhysicalApplicationPath + id + "\\"; //判断路径是否存在 if (!Directory.Exists(path)) { //如果不存在就创建 Directory.CreateDirectory(path); } //产生文件名 string fileName = path + id + "_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + "_" + DateTime.Now.Millisecond.ToString() + ".png"; Stream flstr = new FileStream(fileName, FileMode.Create); BinaryWriter sw = new BinaryWriter(flstr, Encoding.Unicode); sw.Write(buffer); flstr.Close(); sw.Close(); } }}
client:
using UnityEngine;using System.Collections;public class updatePhoto : MonoBehaviour { // Use this for initialization void Start () { StartCoroutine(ScreenShot()); } IEnumerator ScreenShot(){ int width = Screen.width; int height = Screen.height;// string path = Application.dataPath+"/Resources/"; yield return new WaitForEndOfFrame(); Texture2D tex = new Texture2D(width,height,TextureFormat.RGB24,false); tex.ReadPixels(new Rect(0,0,width,height),0,0); //tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); byte[] bytes = tex.EncodeToPNG(); WWWForm newForm = new WWWForm(); newForm.AddField("id","123"); newForm.AddBinaryData("Photo",bytes,"photo.jpg"); WWW w = new WWW("http://localhost:36944/UpdatePhoto.aspx", newForm); while (!w.isDone){yield return new WaitForEndOfFrame();} if (w.error != null){Debug.LogError(w.error);}} }
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;using System.Text;namespace UpdatePhoto{ public partial class UpdatePhoto : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string id = Request.Form["id"]; HttpPostedFile hfc = Request.Files["Photo"]; if (hfc == null) return; Stream sm = hfc.InputStream; byte[] buffer = new byte[sm.Length]; sm.Read(buffer, 0, buffer.Length); sm.Close(); string path = Request.PhysicalApplicationPath + id + "\\"; //判断路径是否存在 if (!Directory.Exists(path)) { //如果不存在就创建 Directory.CreateDirectory(path); } //产生文件名 string fileName = path + id + "_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + "_" + DateTime.Now.Millisecond.ToString() + ".png"; Stream flstr = new FileStream(fileName, FileMode.Create); BinaryWriter sw = new BinaryWriter(flstr, Encoding.Unicode); sw.Write(buffer); flstr.Close(); sw.Close(); } }}
client:
using UnityEngine;using System.Collections;public class updatePhoto : MonoBehaviour { // Use this for initialization void Start () { StartCoroutine(ScreenShot()); } IEnumerator ScreenShot(){ int width = Screen.width; int height = Screen.height;// string path = Application.dataPath+"/Resources/"; yield return new WaitForEndOfFrame(); Texture2D tex = new Texture2D(width,height,TextureFormat.RGB24,false); tex.ReadPixels(new Rect(0,0,width,height),0,0); //tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); byte[] bytes = tex.EncodeToPNG(); WWWForm newForm = new WWWForm(); newForm.AddField("id","123"); newForm.AddBinaryData("Photo",bytes,"photo.jpg"); WWW w = new WWW("http://localhost:36944/UpdatePhoto.aspx", newForm); while (!w.isDone){yield return new WaitForEndOfFrame();} if (w.error != null){Debug.LogError(w.error);}} }
0 0
- Unity3d向web服务器发送数据
- Unity3d向web服务器发送数据
- 向服务器发送数据
- Android向Web服务器发送Post请求并返回数据
- Android向Web服务器发送Post请求并返回数据
- COMET服务器推技术 – 实现Web服务器“主动”向客户端发送数据
- COMET服务器推技术 – 实现Web服务器“主动”向客户端发送数据
- COMET服务器推技术 – 实现Web服务器“主动”向客户端发送数据
- COMET服务器推技术 - 实现Web服务器“主动”向客户端发送数据
- iphone向Web服务器发送图片
- 使用JSON向服务器发送数据
- Ajax - 使用JSON向服务器发送数据
- 用Javascript向服务器发送数据
- C#向服务器发送XML数据
- 使用JSON向服务器发送数据
- 客户端如何向https服务器发送数据
- 服务器向客户端发送数据自动中断
- 安卓向服务器发送List数据
- ZOJ 1037 Gridland
- 我自己做的网站终于上线啦,求围观www.yustock.live
- 完全素数
- Java、Scala、Go以相同方式实现快速排序代码量比较
- 错误处理集锦
- Unity3d向web服务器发送数据
- OLE DB访问接口“MICROSOFT.JET.OLEDB.4.0”配置为在单线程单位模式下运行,所以该访问接口无法用于分布式
- 牛顿迭代法与一道经典编程问题
- 1.获得项目中info.plist文件的内容 2.沙盒的数据存储及读取 3.控制器view的高度和状态栏statusBar的关系 4.[UIScreen mainScreen].application
- QT环境问题
- 我的第一篇博客文章!
- 参考C# 使用 System.Web.Script.Serialization 解析 JSON
- win7 JDK环境变量配置
- Android程序间数据的共享