当前位置: 首页 > news >正文

sql数据库查询网站模板/域名网

sql数据库查询网站模板,域名网,500强企业排名(2022最新名单),怎么搭建自己的网站转载自 脱莫柔Unity3D学习之旅 Unity3D引擎技术交流QQ群:【119706192】本文链接地址: Unity3D 网络通信_HTTP协议:获取网络图片、内容 自己写的测试demo,一个功能一个功能测试着做的,没有什么结构,凑合看吧。 http协议&#xff0c…

转载自 脱莫柔Unity3D学习之旅 Unity3D引擎技术交流QQ群:【119706192本文链接地址: Unity3D 网络通信_HTTP协议:获取网络图片、内容

自己写的测试demo,一个功能一个功能测试着做的,没有什么结构,凑合看吧。

http协议,在手机平台,URL必须必带http://头。

此脚本主要实现了 

  • 分别用pose和get方式获取天气预报信息(XML格式)。
  • 解析XML
  • 获取网络图片
  • 获取网络图片(base64格式)
  • base64与byte[]互转
  • byte[]与Texture2D(图片)互转

更多常用WEBService:http://www.webxml.com.cn/zh_cn/web_services.aspx

  1. using UnityEngine;  
  2. using System.Collections;  
  3. using System.Collections.Generic;  
  4. using System.Xml;  
  5. using System.IO;  
  6.   
  7. public class HTTPDemo : MonoBehaviour  
  8. {  
  9.     public string HostName = "http://www.webxml.com.cn";  
  10.     //城市天气预报服务   
  11.     public string URLPath = "/WebServices/WeatherWebService.asmx/getWeatherbyCityName";  
  12.     //获得验证码服务(直接获得图片)  
  13.     private string PictureName = "/WebServices/ValidateCodeWebService.asmx/cnValidateImage?byString='Picture'";  
  14.     //获得验证码服务(获得图片字节流)  
  15.     private string PictureByteName = "/WebServices/ValidateCodeWebService.asmx/cnValidateByte?byString='picByte'";  
  16.           
  17.     private Texture2D mPicture;  
  18.     private Texture2D mPictureByte;  
  19.     private Texture2D mConvertPNG;  
  20.   
  21.     public string[] Parameters = new string[] { "theCityName" };  
  22.   
  23.     private string XMLContent = "null";  
  24.   
  25.     public string testC = "null";  
  26.   
  27.     void OnGUI()  
  28.     {  
  29.         //显示测试信息   
  30.         GUI.Label(new Rect(100, 10, 1000, 38), testC);  
  31.   
  32.   
  33.         //表单传值  
  34.         if (GUI.Button(new Rect(10, 50, 100, 60), "post"))  
  35.         {  
  36.             postWeatherbyCityName("北京");  
  37.         }  
  38.         GUI.Button(new Rect(120, 80, 100 + getJindu() * 100, 20), (getJindu() * 100) + "%");  
  39.   
  40.   
  41.         //get传值(android平台不支持中文参数)  
  42.         if (GUI.Button(new Rect(10, 130, 100, 60), "get"))  
  43.         {  
  44.             getWeatherbyCityName("58367");//上海  
  45.         }  
  46.         GUI.Button(new Rect(120, 150, 100 + getJindu() * 100, 20), (getJindu() * 100) + "%");  
  47.   
  48.   
  49.    
  50.         //显示读取到的天气预报原始信息(xml格式)  
  51.         GUI.Label(new Rect(10, 220, 380, 500), mContent);  
  52.   
  53.   
  54.   
  55.         //解析xml   
  56.         if (GUI.Button(new Rect(500, 200, 120, 60), "AnalysisXML"))  
  57.         {  
  58.             XMLContent = AnalysisXML();  
  59.         }  
  60.         GUI.Label(new Rect(410, 220, 380, 500), XMLContent);  
  61.   
  62.   
  63.   
  64.         //下载网络图片   
  65.         if (GUI.Button(new Rect(10, 750, 80, 60), "downPic"))  
  66.         {  
  67.             downloadPicture(PictureName);  
  68.         }  
  69.         GUI.Label(new Rect(100, 760, 200, 200), mPicture);  
  70.   
  71.   
  72.         //下载网络图片 (base64格式)  
  73.         if (GUI.Button(new Rect(350, 750, 80, 60), "downPicByte"))  
  74.         {  
  75.             downloadPictureByte(PictureByteName);  
  76.         }  
  77.         GUI.Label(new Rect(450, 760, 200, 200), mPictureByte);  
  78.     }  
  79.   
  80.     public void postWeatherbyCityName(string str)  
  81.     {  
  82.         //将参数集合封装到Dictionary集合方便传值  
  83.         Dictionary<stringstring> dic = new Dictionary<stringstring>();  
  84.   
  85.         //参数  
  86.         dic.Add(Parameters[0], str);  
  87.   
  88.         StartCoroutine(POST(HostName + URLPath , dic));  
  89.     }  
  90.   
  91.     public void getWeatherbyCityName(string str)  
  92.     {  
  93.         //将参数集合封装到Dictionary集合方便传值  
  94.         Dictionary<stringstring> dic = new Dictionary<stringstring>();  
  95.   
  96.         //参数  
  97.         dic.Add(Parameters[0], str);  
  98.   
  99.         StartCoroutine(GET(HostName + URLPath , dic));  
  100.     }  
  101.   
  102.     //下载图片   
  103.     public void downloadPicture(string picName)  
  104.     {  
  105.         testC ="picurl = " + picName;  
  106.   
  107.         StartCoroutine(GETTexture(HostName + picName));  
  108.     }  
  109.   
  110.     //下载图片(字节流)  
  111.     public void downloadPictureByte(string picName)  
  112.     {  
  113.         StartCoroutine(GETTextureByte(HostName + picName));  
  114.     }  
  115.   
  116.     /*----------------------------------------------------Helper----------------------------------------------------------------------------*/  
  117.   
  118.     private float mJindu = 0;  
  119.     private string mContent;  
  120.   
  121.     public float getJindu()  
  122.     {  
  123.         return mJindu;  
  124.     }  
  125.   
  126.     //POST请求(Form表单传值、效率低、安全 ,)  
  127.     IEnumerator POST(string url, Dictionary<stringstring> post)  
  128.     {  
  129.         //表单   
  130.         WWWForm form = new WWWForm();  
  131.         //从集合中取出所有参数,设置表单参数(AddField()).  
  132.         foreach (KeyValuePair<stringstring> post_arg in post)  
  133.         {  
  134.             form.AddField(post_arg.Key, post_arg.Value);  
  135.         }  
  136.         //表单传值,就是post   
  137.         WWW www = new WWW(url, form);  
  138.   
  139.         yield return www;  
  140.         mJindu = www.progress;  
  141.   
  142.         if (www.error != null)  
  143.         {  
  144.             //POST请求失败  
  145.             mContent =  "error :" + www.error;  
  146.         }  
  147.         else  
  148.         {  
  149.             //POST请求成功  
  150.             mContent = www.text;  
  151.         }  
  152.     }  
  153.   
  154.     //GET请求(url?传值、效率高、不安全 )  
  155.     IEnumerator GET(string url, Dictionary<stringstringget)  
  156.     {  
  157.         string Parameters;  
  158.         bool first;  
  159.         if (get.Count > 0)  
  160.         {  
  161.             first = true;  
  162.             Parameters = "?";  
  163.             //从集合中取出所有参数,设置表单参数(AddField()).  
  164.             foreach (KeyValuePair<stringstring> post_arg in get)  
  165.             {  
  166.                 if (first)  
  167.                     first = false;  
  168.                 else  
  169.                     Parameters += "&";  
  170.   
  171.                 Parameters += post_arg.Key + "=" + post_arg.Value;  
  172.             }  
  173.         }  
  174.         else  
  175.         {  
  176.             Parameters = "";  
  177.         }  
  178.   
  179.         testC ="getURL :" + Parameters;  
  180.   
  181.         //直接URL传值就是get  
  182.         WWW www = new WWW(url + Parameters);  
  183.         yield return www;  
  184.         mJindu = www.progress;  
  185.   
  186.         if (www.error != null)  
  187.         {  
  188.             //GET请求失败  
  189.             mContent = "error :" + www.error;  
  190.         }  
  191.         else  
  192.         {  
  193.             //GET请求成功  
  194.             mContent = www.text;  
  195.         }  
  196.     }  
  197.   
  198.     IEnumerator GETTexture(string picURL)  
  199.     {  
  200.         WWW wwwTexture = new WWW(picURL);  
  201.   
  202.         yield return wwwTexture;  
  203.   
  204.         if (wwwTexture.error != null)  
  205.         {  
  206.             //GET请求失败  
  207.             Debug.Log("error :" + wwwTexture.error);  
  208.         }  
  209.         else  
  210.         {  
  211.             //GET请求成功  
  212.             mPicture = wwwTexture.texture;  
  213.         }  
  214.     }  
  215.   
  216.     string PicByte;  
  217.     IEnumerator GETTextureByte(string picURL)  
  218.     {  
  219.         WWW www = new WWW(picURL);  
  220.   
  221.         yield return www;  
  222.   
  223.         if (www.error != null)  
  224.         {  
  225.             //GET请求失败  
  226.             Debug.Log("error :" + www.error);  
  227.         }  
  228.         else  
  229.         {  
  230.             //GET请求成功  
  231.             Debug.Log("PicBytes text = " + www.text);  
  232.   
  233.             XmlDocument xmlDoc = new XmlDocument();  
  234.             xmlDoc.Load(new StringReader(www.text));  
  235.   
  236.             //通过索引查找子节点   
  237.             PicByte = xmlDoc.GetElementsByTagName("base64Binary").Item(0).InnerText;  
  238.             testC = PicByte;  
  239.   
  240.             mPictureByte = BttetoPic(PicByte);  
  241.         }  
  242.     }  
  243.   
  244.     //解析XML   
  245.     string AnalysisXML()  
  246.     {  
  247.         string str = "";  
  248.   
  249.         XmlDocument xmlDoc = new XmlDocument();  
  250.         xmlDoc.Load(new StringReader(mContent));  
  251.   
  252.         //得到文档根节点的所有子节点集合   
  253.         //XmlNodeList nodes = xmlDoc.DocumentElement.ChildNodes;  
  254.         //通过节点名得到节点集合  
  255.         XmlNodeList nodes = xmlDoc.GetElementsByTagName("string");  
  256.   
  257.         //通过索引查找子节点   
  258.         str += "item[1] = " + xmlDoc.GetElementsByTagName("string").Item(1).InnerText + "\n\n";  
  259.   
  260.         //遍历所有子节点  
  261.         foreach (XmlElement element in nodes)  
  262.         {  
  263.             if (element.Name == "string")  
  264.             {  
  265.                 str += element.InnerText + "\n";  
  266.             }  
  267.         }  
  268.           
  269.         return str;  
  270.     }  
  271.   
  272.     //图片与byte[]互转  
  273.     public void convertPNG(Texture2D pic)  
  274.     {  
  275.         byte[] data = pic.EncodeToPNG();  
  276.         Debug.Log("data = " + data.Length + "|" + data[0]);  
  277.         mConvertPNG = new Texture2D(200, 200);  
  278.         mConvertPNG.LoadImage(data);  
  279.     }  
  280.   
  281.     //byte[]与base64互转   
  282.     Texture2D BttetoPic(string base64)  
  283.     {   
  284.         Texture2D pic = new Texture2D(200,200);  
  285.         //将base64转码为byte[]   
  286.         byte[] data = System.Convert.FromBase64String(base64);  
  287.         //加载byte[]图片  
  288.         pic.LoadImage(data);  
  289.   
  290.         string base64str = System.Convert.ToBase64String(data);  
  291.         Debug.Log("base64str = " + base64str);  
  292.   
  293.         return pic;  
  294.     }  
  295. }  

http://www.lbrq.cn/news/1307269.html

相关文章:

  • 做外汇新闻网站/百度seo排名查询
  • 网站优化代码/网站seo推广公司靠谱吗
  • 如何做一网站/软文写作服务
  • 网站制作思路/张家港seo建站
  • 网站如何提高百度排名/传统营销方式有哪些
  • 如何建个使用自己帐户的网站/惠州网站排名提升
  • 网站整体运营思路/百度热搜榜怎么打开
  • 做搜狗pc网站排名/优化大师电脑版官方免费下载
  • 与网站签约/百度一下 你就知道首页官网
  • 做动态网站需要多少钱/seo优化网络推广
  • 哪个网站教做公众号/百度有哪些产品
  • 哪些网站可以做h5/在线查询网站收录
  • 专门做油画交流的网站/新闻式软文经典案例
  • 哪个cms可以做交友网站/网络营销包括的主要内容有
  • 网站设计师对应的专业/深圳谷歌seo公司
  • wordpress文章字号/百度seo网站优化
  • 开发网站能赚多少钱/提交链接
  • 惠州做棋牌网站建设哪家公司便宜/seo资源咨询
  • 网站建设与运营市场开拓方案/百度指数数据分析报告
  • 上海中小企业网站建设/广州aso优化公司 有限公司
  • 网站建设模式/优化网站视频
  • 响应网站怎么做教学视频/关键词查询网站
  • asp网站关键字/seo和sem的区别是什么?
  • 快站app下载/黑锋网seo
  • 独立个人博客网站制作/手机百度识图网页版入口
  • 建立网站如何盈利/昆明seo网站管理
  • 中国建设银行网站密码是什么意思/关键词排名是什么意思
  • 静安网站建设哪里有/百度快速收录技术
  • 南阳锐诚网站建设/搜索引擎最佳化
  • 四川省建设厅网站官网/网上推销产品去什么平台
  • 摩尔投票法:高效寻找数组中的多数元素
  • 智慧农业新图景:物联网如何精准守护作物生长​
  • 鸿蒙和Android知识点
  • 【Java篇】IntelliJ IDEA 安装与基础配置指南
  • Python 基础语法2:组合数据类型、异常
  • 1.1.5 模块与包——AI教你学Django