我有一个可以正常工作的卷发命令。
curl \
-H "Authorization: token some-token" \
-H "Content-Type: video/mp4" \
--data-binary some-video.mp4 \
"https://somewhere.com/upload-handler"
下面是我认为在.NET Core的HttpClient
中的等价物。
using (var stream = File.OpenRead("some-video.mp4"))
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("Authorization", "token some-token");
var streamContent = new StreamContent(stream);
streamContent.Headers.ContentType = new MediaTypeHeaderValue("video/mp4");
var message = await httpClient.PostAsync(
$"https://somewhere.com/upload-handler",
streamContent);
message.EnsureSuccessStatusCode();
}
但是,在运行.NET示例时,我得到了以下内容。
Unhandled exception: System.Net.Http.HttpRequestException: Error while copying content to a stream.
---> System.IO.IOException: Unable to read data from the transport connection: Broken pipe.
---> System.Net.Sockets.SocketException (32): Broken pipe
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Security.SslStream.<WriteSingleChunk>g__CompleteAsync|210_1[TWriteAdapter](ValueTask writeTask, Byte[] bufferToReturn)
at System.Net.Security.SslStream.WriteAsyncChunked[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer)
at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer)
at System.Net.Http.HttpConnection.WriteAsync(ReadOnlyMemory`1 source)
at System.IO.Stream.CopyToAsyncInternal(Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask)
--- End of inner exception stack trace ---
at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask)
at System.Net.Http.HttpConnection.SendRequestContentAsync(HttpRequestMessage request, HttpContentWriteStream stream, CancellationToken cancellationToken)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
我正在运行.NET Core3.1,Ubuntu18.04。
如果这很重要,我正试图通过API: GitHub将二进制文件上传到https://developer.github.com/v3/repos/releases/#upload-a-release-asset发行版中
编辑:我通过查尔斯发送了HttpClient
代码来查看发生了什么,然后它起作用了.:(所以,我没有办法知道出了什么问题。凉爽的。
发布于 2020-05-10 18:12:57
在使用GitHub代码生成中的ubuntu使用dotnet nuget push
命令将nuget包推到dotnet nuget push
包注册表时,我也遇到了类似的错误。我推送多个nuget包,这个错误只偶尔(90%的时间)发生在最大的一个(~5MB)上。
error: Error while copying content to a stream.
error: Unable to read data from the transport connection: Broken pipe.
error: Broken pipe
我正在使用DotNetSDK2.2。
我在任何地方都找不到关于这个错误的任何有用的信息,但是本文给了我一些关于思想https://support.sonatype.com/hc/en-us/articles/360000228868-Artifact-uploads-fail-with-broken-pipe-errors的东西。
https://stackoverflow.com/questions/61160184
复制相似问题