- Home /
This question was
closed Jun 14, 2020 at 11:05 AM by
Fabrizio_1990 for the following reason:
Resolved
Question by
Fabrizio_1990 · Jun 09, 2020 at 08:15 AM ·
downloadwebrequestobj
UnityWebRequest work only on odd tries
I am downloading an obj runtime, but the download call work only on odd tries. if I try to download first time it work, second time is not working (don't go after yield return uwr.SendWebRequest();) the third time is working again and so on... anyone can help me?
IEnumerator GetObjectRoutine(Action<GameObject> callback)
{
GameObject loadedObj = null;
UnityWebRequest.ClearCookieCache();
using (UnityWebRequest uwr = new UnityWebRequest("http://127.0.0.1:8887/Models/174-l2.obj", UnityWebRequest.kHttpVerbGET))
{
string path = Path.Combine(Application.persistentDataPath, "model.obj");
uwr.downloadHandler = new DownloadHandlerFile(path);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
Debug.LogError(uwr.error);
else
{
Debug.Log("File successfully downloaded and saved to " + path);
objectPath = path;
loadedObj = new OBJLoader().Load(path);
downloadedObj = loadedObj;
uwr.Dispose();
}
}
if(loadedObj != null)
callback?.Invoke(loadedObj);
Debug.Log("EXIT FROM GETOBJECT");
}
Comment
Update: I was using chrome web server. when I switched to free webHost it work, also on xampp is working
Follow this Question
Related Questions
Web request pulls html script instead of file text! 1 Answer
See Request of WWW or UnityWebRequest, 403 error only from android in a specific url (GET) 2 Answers
DownloadHandlerAudioClip compressed and streamAudio properties 0 Answers
Convert code from HttpWebRequest to UnityWebRequest (SetRequestHeader) 1 Answer
Android can't download the audio 1 Answer