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

合肥做网站加盟东莞百度搜索网站排名

合肥做网站加盟,东莞百度搜索网站排名,可以做网站背景音乐的英文歌曲,电脑wordpress客服端一、使用BestHTTP实现登录功能(Post) 登录具体的步骤如下: 1:传入你的用户名和密码,这是一条包括链接和用户名密码的链接 2:使用BestHTTP的Post功能将链接传到服务器后台 3:后台拿到了你传送…

一、使用BestHTTP实现登录功能(Post)

登录具体的步骤如下:
1:传入你的用户名和密码,这是一条包括链接和用户名密码的链接
2:使用BestHTTP的Post功能将链接传到服务器后台
3:后台拿到了你传送的包括用户名和密码的链接以后,解析用户名和密码,和数据库中的内容进行比对
4:如果是匹配的就返回true,如果补匹配就返回false

具体的代码如下:

using UnityEngine;
using System;
using BestHTTP;
using LitJson;
using Cysharp.Threading.Tasks;public class ServerManager : Singleton<ServerManager>
{private string root = "http://*************************************";private ResponseResult response;public ResponseResult Response{get => response;}/// <summary>/// 使用异步操作加载/// </summary>/// <param name="username"></param>/// <param name="password"></param>/// <returns></returns>public async UniTask<bool> Login(string username, string password){var url = $"{root}?username={username}&password={password}";HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post);await request.Send();if (request.Exception != null){Debug.Log("请求异常" + request.Exception.Message);return false;}else if (request.Response.IsSuccess){Debug.Log("response success!");string stringResponse = request.Response.DataAsText;response = JsonMapper.ToObject<ResponseResult>(stringResponse);bool isSuccess = response.success;Debug.Log(isSuccess);Debug.Log(response.result);return isSuccess;}return false;}
}
public abstract class Singleton<T> where T : new()
{private static T _instance;private static object _lock = new object();public static T Instance{get{if (_instance == null){lock (_lock){if (_instance == null){_instance = new T();}}}return _instance;}}
}
public class ResponseResult
{public bool success;public string errorMessage;public object data;public string result;
}
private string root = "http://*********";

这是你后台链接,就是你们的服务器IP地址

var url = $"{root}?username={username}&password={password}";

使用字符串拼接把服务器的地址和你的用户名密码拼接在一起,组成一条链接

HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post);
await request.Send();

使用BestHTTP插件把刚才的Url链接Post上去,注意使用HTTPMethods.Post方法,这里因为使用了异步,所以直接用await,不用使用回调函数

string stringResponse = request.Response.DataAsText;
response = JsonMapper.ToObject<ResponseResult>(stringResponse);

这里使用一个字符串从服务器获取到你的内容,然后使用LitJson解析下内容

bool isSuccess = response.success;

后台写好的bool,可以用来判断是否登陆成功

然后登录界面就很简单了

private async void  OnLoginBtnClick(){var res = await ServerManager.Instance.Login(UserField.text, PasswordField.text);if (!res){StartCoroutine(WrongText());}else{SceneManager.LoadScene(1);}}

直接判断你返回的bool就好了!

二、使用BestHTTP实现从后台获取数据(Get)

这个原理和上面是一样的,不过只是get数据

1:传入你的url链接到BestHTTP
2:使用回调函数来执行请求后的操作
3:使用匹配的数据类来解析内容

具体的代码如下:

private string dataURL = "http://cottonhouse.tianfuchuang.cn/admin/data/getData";private IEnumerator SendRequest(){HTTPRequest request = new HTTPRequest(new System.Uri(dataURL), OnRequestFinished);request.Send();yield break;}private void OnRequestFinished(HTTPRequest request, HTTPResponse response){if (request.Exception != null){Debug.Log("请求异常" + request.Exception.Message);return;}try{if (response.IsSuccess){Debug.Log("response success!");//转为textstring stringResponse = response.DataAsText;//转为二进制数组//byte[] results = response.Data;//以WebDataClass的数据类来解析获取到的数据dataClass = JsonMapper.ToObject<WebDataClass>(stringResponse);if (dataClass != null){Debug.Log("解析成功");}
}
}

这里的代码和上面的不同是,这里采用了回调函数OnRequestFinished()

其他是一样的

以上就是使用BestHTTP插件实现Post和Get操作的功能!

http://www.hkea.cn/news/527435/

相关文章:

  • 搭建flv视频网站seo工具查询
  • 企业展示网站 数据库设计模板自助建站
  • 房地产设计师上海seo网络优化
  • wordpress迁移打不开百度seo泛解析代发排名
  • 网站兼容性测试怎么做微信营销软件群发
  • wordpress如何设置内容页seo营销优化
  • 高端大气的网站制作南宁百度seo软件
  • 沙井营销型网站建设成人培训机构
  • 网站没有被百度收录搜索引擎排名优化公司
  • 手机网站转换小程序晋江怎么交换友情链接
  • 专业做网站的公司疫情放开最新消息今天
  • 不用写代码做网站软件长沙优化网站
  • o2o商城网站建设方案广告策划案优秀案例
  • 日照做网站的那家做的好百度网页链接
  • 建设云个人证件查询系统上海seo培训
  • 网站流量提供商杭州seo排名
  • 做装饰工程的在什么网站投标自建站
  • 地球人--一家只做信誉的网站帮忙推广的平台
  • 网站建设外包协议天津网站排名提升
  • 邯郸教育行业网站建设百度推广代理商查询
  • 政府网站有哪些网站seo最新优化方法
  • 做广告牌子seo外链工具
  • 微信页面设计网站兰州网络推广技术
  • 上门做网站搜狗站长工具
  • wordpress用户邮箱验证码百度seo搜索引擎优化培训
  • 360极速怎么屏蔽网站新闻热点大事件
  • 购物app开发价格表站长工具seo排名
  • 微餐饮网站建设营销型网站建设方案
  • 高端网站建设公司好不好2020国内搜索引擎排行榜
  • 网站建设服务公司选哪家比较好?苏州优化收费