我使用HttpClient和PostAsync向服务器发送一个大型视频文件(平均文件大小为50 my )。我得到了一个异常(完整的异常细节见下文)。我发现一篇文章,可以处理的最大文件大小是1mb或更少,这是真的吗?如果是这样,如何增加最大文件大小?
{System.Net.Http.HttpRequestException:发送请求时发生错误--> System.IO.IOException:错误写入请求--> System.Net.Sockets.SocketException:套接字已在System.Net.WebConnection.EndWrite关闭(System.Net.HttpWebRequest请求,System.Boolean throwOnError,(System.IAsyncResult结果) 0x000cc在<2016f34fb49d404d9e9f5c5e62749987>:0 at System.Net.WebConnectionStream.WriteAsyncCB (System.IAsyncResult r) 0x00013 in <2016f34fb49d404d9e9f5c5e62749987>:0 -内部异常堆栈跟踪的末端- at System.Net.WebConnectionStream.EndWrite ( System.IAsyncResult r) 0x000b8 in <2016f34fb49d404d9e9f5c5e62749987>:0 at System.IO.Stream+<>c.b__53_1 (System.IO.Stream流,System.IAsyncResult asyncResult) 0x00000 in :0 at at(包装委托-调用) System.IAsyncResult T2,TResult endMethod,System.IAsyncResult System.IAsyncResult,( System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () 0x0000c in :0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task任务) 0x0003e in :0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task任务) 0x00028 in :0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task任务)0x00008 in :0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () 0x00000 in :0 at System.Net.Http.HttpClientHandler+d__64.MoveNext () 0x0036e in :0 -内部异常堆栈跟踪的结束-在System.Net.Http.HttpClientHandler+d__64.MoveNext () 0x00489 in :0 --堆栈跟踪的前一个位置抛出异常--在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () 0x0000c in :0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task任务) 0x0003e in :0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task任务) 0x00028 in :0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task任务) 0x00008 in :0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <df077aeeed724748974ac70c763795f3>:0 at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000ca] in <e4f3fb4cf2054f718c1099b587ec6f1e>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <df077aeeed724748974ac70c763795f3>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <df077aeeed724748974ac70c763795f3>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <df077aeeed724748974ac70c763795f3>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <df077aeeed724748974ac70c763795f3>:0 at System.Runtime.CompilerServices.TaskAwaiter1TResult.GetResult () 0x00000 in :0 at TBSMobile.View.MainMenu+d__22.MoveNext () 0x00b96 in C:\Users\lawre\source\repos\TBSMobile\TBSMobile\TBSMobile\View\MainMenu.xaml.cs:1088 }
byte[] crVideoData;
if (!string.IsNullOrEmpty(crvideo))
{
crVideoData = File.ReadAllBytes(crvideo);
}
else
{
crVideoData = null;
}
try
{
if (!string.IsNullOrEmpty(crvideo))
{
var vidlink = "http://" + ipaddress + Constants.requestUrl + "Host=" + host + "&Database=" + database + "&Contact=" + contact + "&Request=Lqr9fy";
string vidcontentType = "application/json";
JObject vidjson = new JObject
{
{ "CAFNo", crcafNo },
{ "CAFDate", crcafDate },
{ "Video", crVideoData }
};
HttpClient vidclient = new HttpClient();
var vidresponse = await vidclient.PostAsync(vidlink, new StringContent(vidjson.ToString(), Encoding.UTF8, vidcontentType));
if (vidresponse.IsSuccessStatusCode)
{
await conn.QueryAsync<CAFTable>("UPDATE tblCaf SET LastSync = ? WHERE CAFNo = ?", DateTime.Parse(current_datetime), crcafNo);
}
}
else
{
await conn.QueryAsync<CAFTable>("UPDATE tblCaf SET LastSync = ? WHERE CAFNo = ?", DateTime.Parse(current_datetime), crcafNo);
}
}
catch(Exception ex)
{
Crashes.TrackError(ex);
}发布于 2018-12-21 12:15:08
如果您使用api将上传的视频保存在服务器中,则可能是您的最大请求长度小于您上传的视频大小。如果您想上传高大小的视频,那么在您的webconfig文件中增加最大请求长度。下面是在web项目中增加最大请求长度的示例代码。
<httpRuntime targetFramework="4.5.2" maxRequestLength="15200" />https://stackoverflow.com/questions/53880342
复制相似问题