[英]C# HttpClient broken pipe, but curl works
我有一個正常工作的 curl 命令。
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 Core 3.1、Ubuntu 18.04。
In case it matters, I'm trying to upload a binary to a GitHub release via the API: https://developer.github.com/v3/repos/releases/#upload-a-release-asset
編輯:我通過 Charles 發送了HttpClient
代碼來查看發生了什么,然后它就可以工作了...... :( 所以,我無法判斷出了什么問題。酷。
I get a similar error when trying to push nuget package to GitHub Package Registry using dotnet nuget push
command from an ubuntu build agent in AWS Code Build. 我推送了多個 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
我正在使用 dotnet sdk 2.2。
我在任何地方都找不到有關此錯誤的任何有用信息,但這篇文章讓我有了一些想法-管道錯誤
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.