当前位置:网站首页>Unity C # e-learning (IX) -- wwwfrom
Unity C # e-learning (IX) -- wwwfrom
2022-06-26 15:05:00 【Handsome_ shuai_】
Unity C# E-learning ( Nine )——WWWFrom
- If you want to use WWW When uploading data , We need to cooperate WWWFrom Class
- The main request types used are Post
- Use WWWFrom Uploading data generally needs to cooperate with the back-end program to formulate upload rules
One .WWWFrom class
1.WWWFrom Common methods of class
WWWForm wwwForm = new WWWForm();
//1. Add binary data
wwwForm.AddBinaryData("xxx", new byte[10]);
//2. Add fields
wwwForm.AddField("name", "zzs", Encoding.UTF8);
2.WWW combination WWWFrom Object to asynchronously upload data
private IEnumerator UpLoadData()
{
WWWForm data = new WWWForm();
data.AddField("Name", "zzs", Encoding.UTF8);
data.AddField("Age", 18);
data.AddBinaryData("file",File.ReadAllBytes(Application.streamingAssetsPath +"/test.jpg"),"myTest.jpg","application/octet-stream");
WWW www = new WWW("http://192.168.1.103:8080/Http_Server/", data);
yield return www;
if (www.error == null && www.isDone)
{
Debug.Log(" Upload successful !");
}
else
{
Debug.Log(" Upload failed !" + www.error);
}
}
Two .WWWFrom send data
public void SendMsg<T>(MsgBase msg,Action<T> action) where T: MsgBase
{
StartCoroutine(SendMsgAsync(msg,action));
}
private IEnumerator SendMsgAsync<T>(MsgBase msg,Action<T> action)where T: MsgBase
{
WWWForm wwwForm = new WWWForm();
wwwForm.AddBinaryData("Msg",msg.ToArray());
WWW www = new WWW(RootUrl,wwwForm);
yield return www;
if (www.error == null)
{
int index = 0;
int msgId = BitConverter.ToInt32(www.bytes, 0);
index += 4;
int length = BitConverter.ToInt32(www.bytes, index);
index += 4;
MsgBase msgBase = null;
switch (msgId)
{
case 1001:
msgBase = new PlayerMsg();
msgBase.Reading(www.bytes, index);
break;
}
if (msgBase != null)
{
action?.Invoke(msgBase as T);
}
}
else
{
Debug.Log(" There was a problem sending messages :"+www.error);
}
}
边栏推荐
- 聊聊几位大厂清华同学的近况
- 手机股票注册开户安全吗,有没有什么风险?
- 使用 Abp.Zero 搭建第三方登录模块(二):服务端开发
- View touch analysis
- Login authentication service
- Halcon C # sets the form font and adaptively displays pictures
- RestCloud ETL抽取動態庫錶數據實踐
- R语言dplyr包summarise_at函数计算dataframe数据中多个数据列(通过向量指定)的均值和中位数、指定na.rm参数配置删除缺失值
- MongoDB系列之适用场景和不适用场景
- Informatics Olympiad 1405: sum and product of prime numbers (thinking problem)
猜你喜欢

关于 selenium.common.exceptions.WebDriverException: Message: An unknown server-side error 解决方案(已解决)

Solution to the upper limit of TeamViewer display devices

Smoothing data using convolution

RestCloud ETL解决shell脚本参数化

使用RestCloud ETL Shell组件实现定时调度DataX离线任务

印尼投资部长:鸿海考虑在其新首都建立电动公交系统、城市物联网

使用 Abp.Zero 搭建第三方登录模块(一):原理篇

Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution

Login authentication service

详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型
随机推荐
Unity C# 网络学习(九)——WWWFrom
信息学奥赛一本通 1400:统计单词数 (字符串匹配)
The tablestack function of the epidisplay package of R language makes a statistical summary table (descriptive statistics of groups, hypothesis test, etc.), does not set the by parameter to calculate
[async/await] - the final solution of asynchronous programming
The intersect function in the dplyr package of R language obtains the data lines that exist in both dataframes and the data lines that cross the two dataframes
The JVM outputs GC logs, causing the JVM to get stuck. I am stupid
RestCloud ETL与Kettle对比分析
设计人员拿到的工程坐标系等高线CAD图如何加载进图新地球
程序分析与优化 - 8 寄存器分配
Get the intersection union difference set of two dataframes
feil_uVission4左侧工目录消失
房东拿租金去还房贷是天经地义的嘛
Redis transaction and watch instruction
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
Redis cluster re fragmentation and ask command
Talk about the RPA direction planning: stick to simple and valuable things for a long time
同花顺注册开户安全吗,有没有什么风险?
clustermeet
一键分析硬件/IO/全国网络性能脚本(强推)
Excel-vba quick start (II. Condition judgment and circulation)