c# - C#下载文件并上传相同的文件作为流抛出SocketException
问题描述
我正在尝试重新上传一些文件。为此,我正在获取下载流并用 StreamContent 包装它。然后尝试上传该流。但我总是得到SocketException
。我在这里错过了什么吗?甚至可以将流重定向到另一个地方吗?
_httpClient.DefaultRequestHeaders.Clear();
_httpClient.DefaultRequestHeaders.ConnectionClose = false;
var stream = await _httpClient.GetStreamAsync(fileDownloadInfo.Url);
var streamContent = new StreamContent(stream);
var response = await _httpClient.PutAsync(fileUploadUrl, streamContent); // throws excepiton
这是完整的异常消息:
"InnerException": {
"ClassName": "System.IO.IOException",
"Message": "Unable to read data from the transport connection: An established connection was aborted by the software in your host machine..",
"Data": null,
"InnerException": {
"ClassName": "System.Net.Sockets.SocketException",
"Message": "An established connection was aborted by the software in your host machine.",
"Data": null,
"InnerException": null,
"HelpURL": null,
"StackTraceString": null,
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": null,
"HResult": -2147467259,
"Source": null,
"WatsonBuckets": null,
"NativeErrorCode": 10053
},
"HelpURL": null,
"StackTraceString": " at System.Net.Security.SslStream.<WriteSingleChunk>g__CompleteAsync|210_1[TWriteAdapter](ValueTask writeTask, Byte[] bufferToReturn)\r\n at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer)\r\n at System.Net.Http.HttpConnection.WriteAsync(ReadOnlyMemory`1 source)\r\n at System.Net.Http.HttpConnection.ChunkedEncodingWriteStream.<WriteAsync>g__WriteChunkAsync|2_0(HttpConnection connection, ReadOnlyMemory`1 buffer)\r\n at System.Net.Http.HttpConnection.CopyFromBufferAsync(Stream destination, Int32 count, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpConnection.CopyToContentLengthAsync(Stream destination, UInt64 length, Int32 bufferSize, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpConnection.ContentLengthReadStream.CompleteCopyToAsync(Task copyTask, CancellationToken cancellationToken)\r\n at System.Net.Http.StreamToStreamCopy.<CopyAsync>g__DisposeSourceAsync|0_0(Task copyTask, Stream source)\r\n at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask)",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": null,
"HResult": -2146232800,
"Source": "System.Private.CoreLib",
"WatsonBuckets": null
},
解决方案
推荐阅读
- java - 我的 logcat 到底是什么意思,我该如何解决?
- python - 尝试拆分为训练/测试集时未找到 X 索引
- swift - 使用 DateFormatter().date(from: String) 时返回的日期格式化程序
- laravel - laravel 5.7 多重身份验证电子邮件验证
- ruby - 使用 Ruby 解压有效负载
- flutter - 是否可以将颤振源图或源代码上传到哨兵以便更好地调试?
- c# - 我怎样才能使我的笑脸(用 Windows 窗体制作)相对,这意味着给它一个不同的 (x,y) 坐标,它会保持不变?
- c++ - 从 .msg 文件的标头流中解析日期
- c# - 获取符合特定条件的所有子实体
- visual-studio-2010 - 在 Visual Studio 中调试 C++ 标准库函数