【发布时间】:2016-08-28 20:32:16
【问题描述】:
我正在统一制作一个应用程序,我需要下载一个文件。 我正在使用以下代码来获取标头值:
HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(remoteFile);
request.Method = "HEAD";
HttpWebResponse resp = null;
try {
resp = request.GetResponse() as HttpWebResponse;
}catch (System.Exception e) {
Debug.LogWarning("ERROR: " + e);
return;
}
此代码适用于某些文件,但我在 ge.tt 上托管了一个文件,但它对它不起作用。 我给它的链接会立即在 chrome 中开始下载。
错误是:
ERROR: System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result)
有人知道为什么会这样吗?
谢谢!
【问题讨论】:
-
也许 ge.tt 不支持 HEAD 动词并(错误地)返回 404?尝试做一个简单的 GET。
-
感谢您的回答,我已尝试 GET 并收到“请求超时”。这很奇怪
-
也许您在 url 中使用的是“https:”而不是“http:”?
-
是的,我使用的是 https,当我尝试使用 http 的 url 时,它会给出以下错误:“写入:身份验证或解密失败。”
-
好的,我查找了新问题并找到了解决方法,谢谢!
标签: c# .net unity3d httpwebrequest httpwebresponse