[英]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.