【发布时间】:2019-03-07 11:29:45
【问题描述】:
我复制没有问题的小文件。 当用户尝试上传大尺寸文件(我猜 > 60MB)时,我遇到了网络异常(404 Not Found)。
我很确定问题出在文件大小上。我在
遇到了异常webRequest.GetResponse()
我需要修改服务器端吗? 任何建议都值得赞赏。
public static bool UploadFile(IResult result, string pathFile, Stream stream)
{
// upload effettivo del file su DB
HttpWebRequest webRequest = WebRequest.Create(ClientCommon.Properties.Settings.Default.FileServiceURI) as HttpWebRequest;
HttpWebResponse response = null;
Stream s = null;
try
{
webRequest.Method = WebRequestMethods.Http.Post;
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.KeepAlive = true;
using (WebRequestBuilder wrb = new WebRequestBuilder())
{
webRequest.ContentType = wrb.ContentType;
wrb.AddTextPart("cdFile", pathFile);
wrb.AddFilePart("file", stream);
wrb.AddTextPart("destination", pathFile);
if (wrb.GetContent(result, out s) == false)
return false;
s.CopyTo(webRequest.GetRequestStream());
}
response = webRequest.GetResponse() as HttpWebResponse;
return true;
}
catch (WebException exc)
{
result.SetError(exc.Message);
return false;
}
finally
{
if (response != null)
response.Close();
if (s != null)
// When the above code has ended, close the streams
s.Close();
}
}
【问题讨论】:
-
服务器是否有请求大小限制?
-
您使用的是哪个应用程序
WebAPI、WebAPI Core等等? -
尝试在
httpRuntime中设置属性maxRequestLength="2147483647"在system.web中的web.config中 -
尝试添加这个 =>
<security> <requestFiltering> <requestLimits maxAllowedContentLength="2147483647" /> </requestFiltering> </security>内<system.webServer>并让我知道 -
是的,很高兴听到,我将其添加为答案 :)
标签: c# http-status-code-404 httpwebrequest httpwebresponse