Search Unity

[Solved] WebGL. No response headers.

Discussion in 'Web' started by Nimonymous, Jan 4, 2019.

  1. Nimonymous

    Nimonymous

    Joined:
    Jul 15, 2016
    Posts:
    9
    Hi! In my WEBGL project, i download an assetbundle from the server and i want to make some progressbar for it. So, in editor everything works, i get Content-Length header and www.downloadedprogress returns the correct value. But in browser, the collection of headers is empty and progress is always 0 :(

    I tried to get Content-Length header by HEAD request, but it returns empty collection as well.
    Heres my code:
    Code (CSharp):
    1.  IEnumerator DownloadSceneAsset()
    2.     {
    3.         using (UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url))
    4.         {
    5.             StartCoroutine(ShowProgress(www));
    6.  
    7.             yield return www.SendWebRequest();
    8.  
    9.             AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(www);
    10.             //some other code here...
    11.         }
    12.     }
    13.  
    14.     IEnumerator ShowProgress(UnityWebRequest www)
    15.     {
    16.         while (!www.isDone)
    17.         {
    18.             progress.text = (www.downloadProgress * 100f).ToString("0") + "%";
    19.  
    20.             yield return null;
    21.         }
    22.     }
    And tried this:
    Code (CSharp):
    1.     IEnumerator GetContenSize()
    2.     {
    3.         using (UnityWebRequest www = UnityWebRequest.Head(url))
    4.         {
    5.             yield return www.SendWebRequest();
    6.  
    7.             print(www.GetResponseHeaders().ContainsKey("Content-Length"));
    8. ...
    9.  
    10.             foreach (var item in www.GetResponseHeaders())
    11.             {
    12.                 print(item.Key + " | " + item.Value);
    13.             }
    14.         }
    15.     }
    No cors problems, the client has been hosted. Everything works exept i dont know the progress of downloading in webgl build.
    Thx!
     
    Last edited: Jan 4, 2019
  2. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598

    Can you try :

    Code (CSharp):
    1.     IEnumerator DownloadSceneAsset()
    2.     {
    3.  
    4.         UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url);
    5.         www.SendWebRequest();
    6.  
    7.         while (!www.isDone)
    8.         {
    9.             progress.text = (www.downloadProgress * 100f).ToString("0") + "%";
    10.  
    11.             yield return null;
    12.         }
    13.  
    14.         AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(www);
    15.  
    16.     }
     
  3. Nimonymous

    Nimonymous

    Joined:
    Jul 15, 2016
    Posts:
    9
    Solution: add .swf extension to the AssetBundle file.
    It's all because of Cloudflare protection.
     
  4. wechat_os_Qy07am7Wy1_qI2hEgygU9lgVI

    wechat_os_Qy07am7Wy1_qI2hEgygU9lgVI

    Joined:
    Aug 10, 2019
    Posts:
    48
    how do u do that? i did what u said with the same result,pls help
     
  5. wechat_os_Qy07am7Wy1_qI2hEgygU9lgVI

    wechat_os_Qy07am7Wy1_qI2hEgygU9lgVI

    Joined:
    Aug 10, 2019
    Posts:
    48
    this is my htacess:

    AddType application/x-shockwave-flash .swf
    <IfModule mod_mime.c>
    AddEncoding gzip .unityweb
    </IfModule>