Unity3d 在unity中,下载第101个文件时使用WebClient.DownloadFileAsync和WebClient timeout
我在unity中使用webclient.DownloadFileAsync来下载大量文件。 在安卓系统上,这一点很有效 但问题是:在iOS上,webclient会一直挂起,直到下载第101个文件时超时Unity3d 在unity中,下载第101个文件时使用WebClient.DownloadFileAsync和WebClient timeout,unity3d,nginx,webclient,downloadfile,Unity3d,Nginx,Webclient,Downloadfile,我在unity中使用webclient.DownloadFileAsync来下载大量文件。 在安卓系统上,这一点很有效 但问题是:在iOS上,webclient会一直挂起,直到下载第101个文件时超时 // begin download ServicePointManager.DefaultConnectionLimit = 50; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointMan
// begin download
ServicePointManager.DefaultConnectionLimit = 50;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.Expect100Continue = false;
// create one WebClient for one file
client = new WebClientWithTimeout();
client.Timeout = 10000;
// add headers, at beginning, i don't add any headers,after some search,i have try this headers,but not work
client.Headers.Add("User-Agent", "Mozilla/5.0");
client.Headers.Add("Accept", "ext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
client.Headers.Add("Encoding", "gzip, deflate;q=0.8");
client.DownloadProgressChanged += ProgressChanged;
client.DownloadFileCompleted += DownloadCompleted;
client.DownloadFileAsync(new System.Uri(curUrl), curDownFile);
// this is the WebClientWithTimeout for set timeout
public class WebClientWithTimeout : WebClient
{
public int Timeout { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = (WebRequest)base.GetWebRequest(address);
if (request is HttpWebRequest)
{
var httpReq = request as HttpWebRequest;
httpReq.Proxy = null;
httpReq.ServicePoint.Expect100Continue = false;
httpReq.AllowAutoRedirect = true;
httpReq.Timeout = Timeout;
}
return request;
}
}
对于文件服务器,它是一个nginx(不在本地网络上),当我在本地网络上使用带有caddy的文件服务器时,这个问题不会发生。
我不擅长服务器,我想我可能错过了很多关于nginx的基础知识
---更多信息
webclient不在同一时间逐个下载文件。是否可能是iOS将同时传出的连接数量限制为100,因此您也必须将其限制为该数量?@PhilippLenssen,对不起,我忘记了此信息。我使用WebClient一个接一个地下载文件,而不是同时下载。一般来说:为什么不使用
UnityWebRequest
?@derHugo谢谢你的留言。是的,我可以使用UnityWebRequest,甚至更多,我可以使用HttpWebRequest,但我仍然不知道为什么这个WebClient不能在iOS上工作,可能WebClient有一个bug,或者nginx有一些设置,我想解决这个问题。问题出在下载的数量,而在内容大小上?也许在下载100次后,您达到了下载大小限制?也许仅仅第101个请求就是一个本身太大的特定文件?