以发送Get 和 Post请求 返回json字符串为例:
发送Post请求:
protected IEnumerator SendPost(string url, WWWForm wForm = null)
{
if (!string.IsNullOrEmpty(url))
{
WWW result = new WWW(url, wForm);
yield return result;
if (result.error != null)
{
Debug.Log("访问失败:" + result.error);
}
else
{
if (string.IsNullOrEmpty(result.text))
{
Debug.LogError("返回值为空");
}
else
{
Debug.Log(result.text);
}
}
}
else
{
Debug.LogError("URL不能为空");
}
}
发送Get请求:
protected IEnumerator SendGet(string url)
{
if (!string.IsNullOrEmpty(url))
{