请求数据
public void PostCode(string phone)
{
//Debug.Log("获取验证码");
StartCoroutine(PostCODE(phone, PostCodeCallBack));
}
public IEnumerator PostCODE(string phone, Action<JsonData> callback = null)
{
JsonData data = new JsonData();
//如果还别的请求参数,参考下面方式加就完事了
data["mobile"] = phone;
string jsonDatas = JsonMapper.ToJson(data);
string url = "http://192.168.1.7:48000/api/v1/user/getCode";
using (UnityWebRequest req = UnityWebRequest.Post(url, jsonDatas, "application/json"))
{
yield return req.SendWebRequest();
JsonData jsonData = JsonMapper.ToObject(req.downloadHandler.text);
callback(jsonData);
}
}
/// <summary>
/// 回调
/// </summary>
/// <param name="jsonData"></param>
private void PostCodeCallBack(JsonData jsonData)
{
//Debug.Log(jsonData["code"].ToString());
//Debug.Log(jsonData["msg"].ToString());
if (jsonData["code"].ToString() == "0")
{
//Debug.Log("登录成功!!!");
}
else
{
Debug.Log("登录失败!!!");
//OnShowLoginCode(jsonData["msg"].ToString(), true);
}
}
注意:要引用 listjson