当前位置:网站首页>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);
}
}
边栏推荐
- Document 1
- Is it safe to open an online stock account? Somebody give me an answer
- 北京银行x华为:网络智能运维夯实数字化转型服务底座
- It's natural for the landlord to take the rent to repay the mortgage
- Complimentary Book Cognitive Control: how does our brain accomplish tasks?
- Mathematical modeling of war preparation 30 regression analysis 2
- What is the ranking of Guosen Securities? Is it safe to open a stock account?
- Talk about the RPA direction planning: stick to simple and valuable things for a long time
- Solution to the upper limit of TeamViewer display devices
- [solo π] ADB connects multiple mobile phones
猜你喜欢
【soloπ】adb连接单个多个手机
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
Notes on writing questions in C language -- table tennis competition
RestCloud ETL抽取動態庫錶數據實踐
BLE抓包调试信息分析
About selenium common. exceptions. Webdriverexception: message: an unknown server side error solution (resolved)
Login authentication service
[solo π] ADB connects multiple mobile phones
JVM 输出 GC 日志导致 JVM 卡住,我 TM 人傻了
Mark一下 Unity3d在Inspector中选中不了资源即Project锁定问题
随机推荐
R language GLM function logistic regression model, using epidisplay package logistic The display function obtains the summary statistical information of the model (initial and adjusted odds ratio and
设计人员拿到的工程坐标系等高线CAD图如何加载进图新地球
R语言glm函数逻辑回归模型、使用epiDisplay包logistic.display函数获取模型汇总统计信息(自变量初始和调整后的优势比及置信区间,回归系数的Wald检验的p值)、结果保存到csv
使用RestCloud ETL Shell组件实现定时调度DataX离线任务
Redis事务与watch指令
ETL过程中数据精度不准确问题
使用 Abp.Zero 搭建第三方登录模块(二):服务端开发
重磅白皮书发布,华为持续引领未来智慧园区建设新模式
Optimizing for vectorization
R语言epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布、使用cex.X.axis参数指定X轴轴刻度数值标签字体的大小
Halcon C# 设置窗体字体,自适应显示图片
TCP 复位攻击原理
Attention meets Geometry:几何引导的时空注意一致性自监督单目深度估计
Is it safe to open a stock account with the account manager online??
The engine "node" is inconsistent with this module
【云原生】 ”人人皆可“ 编程的无代码 iVX 编辑器
RestCloud ETL与Kettle对比分析
编译配置in文件
人力资源导出数据 excel VBA
5张图诠释了容器网络