unity UnityWebRequest 的request.downloadHandler 空应用
unity UnityWebRequest 的request.downloadHandler 空应用
private IEnumerator Test_Get()
{
UnityWebRequest request = new UnityWebRequest(tmp_getURL, "GET");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError($"Post Error: {request.error}");
}
else
{
Debug.Log($"Post Success: {request.downloadHandler.text}");
}
}
解决办法
创建一个 DownloadHandlerBuffer 对象。
private IEnumerator Test_Get()
{
UnityWebRequest request = UnityWebRequest.Get(tmp_getURL);
request.downloadHandler = new DownloadHandlerBuffer(); // 确保有下载处理器
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError($"Get Error: {request.error}");
}
else
{
Debug.Log($"Get Success: {request.downloadHandler.text}");
}
}