简体   繁体   English

内容长度适用于某些文件类型和不同的操作系统?

[英]Content-length works for some file type and in different OS?

I want to get length of my some type of file from my server like : .mp4 , .xml , .png , and custom file type .500 !我想从我的服务器获取某种类型文件的长度,例如:.mp4、.xml、.png 和自定义文件类型 .500!

I printed length with C# code in unity with :我用 C# 代码统一打印了长度:

public class Tmp_ContentLength : MonoBehaviour {
    public List<string> urls = new List<string> ();


    void Start () {

        for (int i = 0; i < urls.Count; i++) {
            print (urls[i]);

            StartCoroutine (GetFileSize (urls[i],
                (size) => {
                   print ("File Size::> " + size);

                }));
        }
    }

    IEnumerator GetFileSize (string url, Action<Int32> result) {
        UnityWebRequest uwr = UnityWebRequest.Head (url);
        yield return uwr.SendWebRequest ();
        string size = uwr.GetResponseHeader ("Content-Length");

        if (uwr.isNetworkError || uwr.isHttpError) {
            print("Error While Getting Length: " + uwr.error);
            if (result != null)
                result (-1);
        } else {
            if (result != null)
                result (Convert.ToInt32 (size));
        }
    }
}

urls field fill with true Urls in inspector. urls 字段在检查器中填充真实的 URL。

So, I can get length of all files in unity editor, but when I export .apk and run it, I will get print of .mp4 and .png , not .xml and .500(my custom file type ) .所以,我可以在统一编辑器中获取所有文件的长度,但是当我导出 .apk 并运行它时,我将打印 .mp4 和 .png ,而不是 .xml 和 .500(my custom file type ) 。

1- Is there any issue or I,m wrong? 1- 有什么问题还是我错了? 2- How can I enable Content-length header for .xml and my custom file type? 2- 如何为 .xml 和我的自定义文件类型启用内容长度标头? 3- What is different between unity editor and android for get Content-length ? 3- unity editor 和 android 在获取 Content-length 方面有什么不同?

Best Regards and sorry for bad English!最好的问候和糟糕的英语抱歉!

So, After try over and over!所以,经过反复尝试! I found we need to disable gzip on sever and I do it with .htaccess files我发现我们需要在服务器上禁用gzip ,我使用.htaccess文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 API响应:StatusCode:0,Content-Type :, Content-Length:0 - API response : StatusCode: 0, Content-Type: , Content-Length: 0 获取没有内容长度的远程文件大小 - Getting remote file size without content-length ASP.net MVC文件内容长度 - ASP.net MVC File Content-Length 如何使用Content#Length在C#中下载文件:0 - How to download file in C# with Content-Length: 0 下载文件,我得到Content-Length标头无效 - Downloading a file, and I get Content-Length header is Invalid 响应 header 的 Content-Length 小于实际文件大小 - Content-Length of the response header is less than the actual file size FileResult 内容长度不匹配 - FileResult content-length mismatch WebResponse Content-Length返回-1 - WebResponse Content-Length Returns -1 restsharp PUT 请求错误--&gt;“StatusCode: InternalServerError, Content-Type: application/json, Content-Length: -1)” - restsharp PUT request error --> "StatusCode: InternalServerError, Content-Type: application/json, Content-Length: -1)" 如何将Content-Length,Content-Type和Last-Modified添加到HTTP响应消息头中 - How to add the Content-Length,Content-Type and Last-Modified to the HTTP Response Message Header
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM