IEnumerator GetEnumerator(string url, string accounts,string password)
{
// Debug.Log(url + " " + accounts + " " + password);
string input = "{\"username\":\"" + accounts + "\",\"password\":\"" + password + "\"}";
byte[] rawData = Encoding.UTF8.GetBytes(input);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers["Content-Type"] = "application/json";
headers["Accept"] = "application/json";
WWW getdata = new WWW(url, rawData, headers);
yield return getdata;
if (getdata.isDone && string.IsNullOrEmpty(getdata.error))
{
JsonData data = JsonMapper.ToObject(getdata.text);
if (data["res"].ToString() == "True")
{
}
}
}
Pos-->UnityWebRequest
WWWForm wWW = new WWWForm();
wWW.AddField("username", accounts);
wWW.AddField("password", password);
wWW.headers["Content-Type"] = "application/json";
using (UnityWebRequest request = UnityWebRequest.Post(url,wWW))
{
yield return request.SendWebRequest();
if (request.isDone && !request.isHttpError&&!request.isNetworkError&& request.responseCode.ToString()=="200")
{
JsonData data = JsonMapper.ToObject(request.downloadHandler.text);
}
}
/***********************************Async(不适用于webgl)***********************************/
public static async void Get_AsyncCallback(string url,Action<string> Info)
{
using (HttpClient request = new HttpClient())
{
var Text= await request.GetStringAsync(url);
if (!string.IsNullOrEmpty(Text))
{
Info?.Invoke(Text);
}
}
}