{"id":197,"date":"2023-01-15T21:14:29","date_gmt":"2023-01-16T05:14:29","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/?p=197"},"modified":"2023-02-15T04:15:49","modified_gmt":"2023-02-15T12:15:49","slug":"net-7%e6%9b%b4%e6%96%b0%e4%b9%8b%e7%bd%91%e7%bb%9c%ef%bc%8c%e6%98%af%e4%bd%a0%e6%9c%9f%e5%be%85%e7%9a%84%e5%90%97","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/net-7%e6%9b%b4%e6%96%b0%e4%b9%8b%e7%bd%91%e7%bb%9c%ef%bc%8c%e6%98%af%e4%bd%a0%e6%9c%9f%e5%be%85%e7%9a%84%e5%90%97\/","title":{"rendered":".NET 7\u66f4\u65b0\u4e4b\u7f51\u7edc\uff0c\u662f\u4f60\u671f\u5f85\u7684\u5417?"},"content":{"rendered":"<p>\u6700\u65b0\u7684<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-7\/\">.NET 7<\/a>\u73b0\u5df2\u53d1\u5e03\uff0c\u6211\u4eec\u60f3\u4ecb\u7ecd\u4e00\u4e0b\u5176\u5728\u7f51\u7edc\u9886\u57df\u6240\u505a\u7684\u4e00\u4e9b\u6709\u8da3\u7684\u66f4\u6539\u548c\u6dfb\u52a0\u3002\u8fd9\u7bc7\u535a\u6587\u8ba8\u8bba\u4e86 .NET 7 \u5728<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/dotnet-7-networking-improvements\/#http\">HTTP \u7a7a\u95f4<\/a>\u3001<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/dotnet-7-networking-improvements\/#quic\">\u65b0 QUIC API<\/a>\u3001<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/dotnet-7-networking-improvements\/#security\" lang=\"zh-CN\">\u7f51\u7edc\u5b89\u5168<\/a>\u548c<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/dotnet-7-networking-improvements\/#websockets\">WebSockets<\/a>\u65b9\u9762\u7684\u53d8\u5316\u3002<\/p>\n<h3>HTTP<\/h3>\n<h3 lang=\"zh-CN\">\u6539\u8fdb\u4e86\u5bf9\u8fde\u63a5\u5c1d\u8bd5\u5931\u8d25\u7684\u5904\u7406<\/h3>\n<p>\u5728 .NET 6 \u4e4b\u524d\u7684\u7248\u672c\u4e2d\uff0c\u5982\u679c\u8fde\u63a5\u6c60\u4e2d\u6ca1\u6709\u7acb\u5373\u53ef\u7528\u7684\u8fde\u63a5\uff0c\uff08\u5904\u7406\u7a0b\u5e8f\u4e0a\u7684\u8bbe\u7f6e\u5141\u8bb8\u7684\u60c5\u51b5\u4e0b\uff0c\u4f8b\u5982HTTP \/1.1\u4e2d\u7684MaxConnectionsPerServer\uff0c\u6216 HTTP\/2\u4e2d\u7684EnableMultipleHttp2Connections\uff09\u65b0\u7684 HTTP \u8bf7\u6c42\u59cb\u7ec8\u4f1a\u53d1\u8d77\u65b0\u7684\u8fde\u63a5\u5c1d\u8bd5\u5e76\u7b49\u5f85\u54cd\u5e94\u3002\u8fd9\u6837\u505a\u7684\u7f3a\u70b9\u662f\uff0c\u5efa\u7acb\u8be5\u8fde\u63a5\u9700\u8981\u4e00\u6bb5\u65f6\u95f4\uff0c\u800c\u5728\u8fd9\u6bb5\u65f6\u95f4\u91cc\u5982\u679c\u53e6\u4e00\u4e2a\u8fde\u63a5\u5df2\u7ecf\u53ef\u7528\uff0c\u8be5\u8bf7\u6c42\u4ecd\u5c06\u7ee7\u7eed\u7b49\u5f85\u5b83\u751f\u6210\u7684\u8fde\u63a5\uff0c\u4ece\u800c\u5f71\u54cd\u5ef6\u8fdf\u3002\u5728 .NET 6.0<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/dotnet-6-networking-improvements\/#other-http-changes\">\u4e2d\u6211\u4eec\u6539\u53d8\u4e86\u8fd9\u4e00\u8fdb\u7a0b<\/a>\uff0c\u65e0\u8bba\u662f\u65b0\u5efa\u7acb\u7684\u8fde\u63a5\u8fd8\u662f\u4e0e\u6b64\u540c\u65f6\u51c6\u5907\u597d\u5904\u7406\u8bf7\u6c42\u7684\u53e6\u4e00\u4e2a\u8fde\u63a5\uff0c\u7b2c\u4e00\u4e2a\u53ef\u7528\u7684\u8fde\u63a5\u4f1a\u5904\u7406\u8bf7\u6c42\u3002\u8fd9\u6837\u4ecd\u4f1a\u4e00\u4e2a\u65b0\u8fde\u63a5\u88ab\u5efa\u7acb\uff08\u53d7\u9650\u5236\uff09\uff0c\u5982\u679c\u53d1\u8d77\u7684\u8bf7\u6c42\u672a\u4f7f\u7528\u8fd9\u4e00\u8fde\u63a5\uff0c\u5219\u5b83\u4f1a\u88ab\u5408\u5e76\u4ee5\u4f9b\u540e\u7eed\u8bf7\u6c42\u4f7f\u7528\u3002<\/p>\n<p>\u4e0d\u5e78\u7684\u662f\uff0c.NET 6.0 \u4e2d\u7684\u8fd9\u4e00\u529f\u80fd\u5bf9\u67d0\u4e9b\u7528\u6237\u6765\u8bf4\u662f\u6709\u95ee\u9898\u7684\uff1a\u5931\u8d25\u7684\u8fde\u63a5\u5c1d\u8bd5\u4e5f\u4f1a\u4f7f\u4f4d\u4e8e\u8bf7\u6c42\u961f\u5217\u9876\u90e8\u7684\u8bf7\u6c42\u5931\u8d25\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5728<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/60654#issue-1030717005\">\u67d0\u4e9b\u60c5\u51b5\u4e0b<\/a>\u5bfc\u81f4\u610f\u5916\u7684\u8bf7\u6c42\u5931\u8d25\u3002\u6b64\u5916\uff0c\u5982\u679c\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\uff08\u4f8b\u5982\u7531\u4e8e\u670d\u52a1\u5668\u884c\u4e3a\u4e0d\u5f53\u6216\u7f51\u7edc\u95ee\u9898\uff09\u6c60\u4e2d\u6709\u4e00\u4e2a\u6c38\u8fdc\u672a\u88ab\u4f7f\u7528\u7684\u8fde\u63a5\uff0c\u4e0e\u4e4b\u5173\u8054\u7684\u65b0\u4f20\u5165\u7684\u8bf7\u6c42\u4e5f\u5c06\u5ef6\u8fdf\u5e76\u53ef\u80fd\u8d85\u65f6\u3002<\/p>\n<p>\u5728 .NET 7.0 \u4e2d\uff0c\u6211\u4eec\u5b9e\u65bd\u4e86\u4ee5\u4e0b\u66f4\u6539\u6765\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u5931\u8d25\u7684\u8fde\u63a5\u5c1d\u8bd5\u53ea\u80fd\u4f7f\u5176\u76f8\u5173\u7684\u53d1\u8d77\u8bf7\u6c42\u5931\u8d25\uff0c\u800c\u4e0d\u4f1a\u5bfc\u81f4\u65e0\u5173\u7684\u8bf7\u6c42\u5931\u8d25\u3002\u5982\u679c\u5728\u8fde\u63a5\u5931\u8d25\u65f6\u539f\u59cb\u8bf7\u6c42\u5df2\u5f97\u5230\u5904\u7406\uff0c\u5219\u8fde\u63a5\u5931\u8d25\u5c06\u88ab\u5ffd\u7565 (\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/62935\">dotnet\/runtime#62935<\/a>\u00a0)\u3002<\/li>\n<li>\u5982\u679c\u4e00\u4e2a\u8bf7\u6c42\u53d1\u8d77\u4e86\u4e00\u4e2a\u65b0\u8fde\u63a5\uff0c\u4f46\u968f\u540e\u88ab\u6c60\u4e2d\u7684\u53e6\u4e00\u4e2a\u8fde\u63a5\u5904\u7406\uff0c\u5219\u65b0\u7684\u5f85\u4f7f\u7528\u7684\u8fde\u63a5\u5c1d\u8bd5\u5c06\u4e0d\u7ba1ConnectTimeout\uff0c\u5728\u77ed\u65f6\u95f4\u540e\u81ea\u52a8\u8d85\u65f6\u3002\u901a\u8fc7\u6b64\u66f4\u6539\uff0c\u5ef6\u8fdf\u7684\u8fde\u63a5\u5c06\u4e0d\u4f1a\u5ef6\u8fdf\u4e0d\u76f8\u5173\u7684\u8bf7\u6c42 (\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/71785\">dotnet\/runtime#71785<\/a>\u00a0)\u3002\u8bf7\u6ce8\u610f\uff0c\u4e0d\u88ab\u4f7f\u7528\u7684\u8fde\u63a5\u5c1d\u8bd5\u81ea\u52a8\u8d85\u65f6\u5931\u8d25\u7684\u8fd9\u4e00\u8fdb\u7a0b\u53ea\u4f1a\u5728\u540e\u53f0\u81ea\u5df1\u8fd0\u884c\uff0c\u7528\u6237\u4e0d\u4f1a\u770b\u5230\u6b64\u8fdb\u7a0b\u3002\u89c2\u5bdf\u5b83\u4eec\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u542f\u7528telemetry\u3002<\/li>\n<\/ul>\n<h3>HttpHeaders \u8bfb\u53d6\u7ebf\u7a0b\u5b89\u5168<\/h3>\n<p>\u8fd9\u4e9bHttpHeaders\u96c6\u5408\u4ece\u6765\u90fd\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u8bbf\u95eeheader\u53ef\u80fd\u4f1a\u5f3a\u5236\u5ef6\u8fdf\u89e3\u6790\u5b83\u7684\u503c\uff0c\u4ece\u800c\u5bfc\u81f4\u5bf9\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u7684\u4fee\u6539\u3002<\/p>\n<p>\u5728 .NET 6 \u4e4b\u524d\uff0c\u540c\u65f6\u8bfb\u53d6\u96c6\u5408\u5728<em>\u5927\u591a\u6570<\/em>\u60c5\u51b5\u4e0b\u6070\u597d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002<\/p>\n<p>\u4ece .NET 6 \u5f00\u59cb\uff0c\u7531\u4e8e\u5185\u90e8\u4e0d\u518d\u9700\u8981\u9501\u5b9a\uff0c\u9488\u5bf9header\u89e3\u6790\u6267\u884c\u7684\u9501\u5b9a\u8f83\u5c11\u3002\u8fd9\u4e00\u53d8\u5316\u5bfc\u81f4\u8bb8\u591a\u7528\u6237\u9519\u8bef\u5730\u540c\u65f6\u8bbf\u95eeheader\uff0c\u4f8b\u5982\uff0c\u5728 gRPC (\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/55898\">dotnet\/runtime#55898<\/a>\u00a0)\u3001NewRelic (\u00a0<a href=\"https:\/\/github.com\/newrelic\/newrelic-dotnet-agent\/issues\/803\">newrelic\/newrelic-dotnet-agent#803<\/a>\u00a0) \u751a\u81f3 HttpClient \u672c\u8eab (\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/65379\">dotnet\/runtime #65379<\/a>\uff09\u3002\u8fdd\u53cd .NET 6 \u4e2d\u7684\u7ebf\u7a0b\u5b89\u5168\u53ef\u80fd\u4f1a\u5bfc\u81f4header\u503c\u91cd\u590d\/\u683c\u5f0f\u9519\u8bef\u6216\u5728\u679a\u4e3e\uff08enumeration\uff09\/header\u8bbf\u95ee\u671f\u95f4\u4ea7\u751f\u5404\u79cd\u5f02\u5e38\u3002<\/p>\n<p>.NET 7 \u4f7fheader\u884c\u4e3a\u66f4\u52a0\u76f4\u89c2\u3002\u8be5HttpHeaders\u96c6\u5408\u73b0\u5728\u7b26\u5408Dictionary\u7ebf\u7a0b\u5b89\u5168\u4fdd\u8bc1\uff1a<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">\u96c6\u5408\u53ef\u4ee5\u540c\u65f6\u652f\u6301\u591a\u4e2a\u8bfb\u8005\uff0c\u53ea\u8981\u5b83\u4e0d\u88ab\u4fee\u6539\u3002\u6781\u5c11\u6570\u60c5\u51b5\u4e0b\uff0c\u679a\u4e3e\uff08enumeration\uff09\u4e0e\u4e66\u5199\u8bbf\u95ee\u6743\u9650\u4e89\u7528\uff0c\u5219\u8be5\u96c6\u5408\u5fc5\u987b\u5728\u6574\u4e2a\u679a\u4e3e\u671f\u95f4\u88ab\u9501\u5b9a\u3002\u8981\u5141\u8bb8\u591a\u4e2a\u7ebf\u7a0b\u8bbf\u95ee\u96c6\u5408\u4ee5\u540c\u65f6\u8fdb\u884c\u8bfb\u5199\uff0c\u60a8\u5fc5\u987b\u5b9e\u73b0\u81ea\u5df1\u7684\u540c\u6b65\u3002<\/code><\/pre>\n<p>\u8fd9\u662f\u901a\u8fc7\u4ee5\u4e0b\u66f4\u6539\u5b9e\u73b0\u7684\uff1a<\/p>\n<ul>\n<li>\u65e0\u6548\u503c\u7684\u201c\u9a8c\u8bc1\u8bfb\u53d6\u201d\u4e0d\u4f1a\u5220\u9664\u65e0\u6548\u503c \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/67833\">dotnet\/runtime#67833<\/a>\uff08\u611f\u8c22<a href=\"https:\/\/translate.google.com\/website?sl=auto&amp;tl=zh-CN&amp;hl=en&amp;u=https:\/\/github.com\/heathbm\">@heathbm<\/a>\uff09\u3002<\/li>\n<li>\u540c\u65f6\u8bfb\u53d6\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u2014\u2014<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/68115\">dotnet\/runtime#68115<\/a>\u3002<\/li>\n<\/ul>\n<h3>\u68c0\u6d4b HTTP\/2 \u548c HTTP\/3 \u534f\u8bae\u9519\u8bef<\/h3>\n<p>HTTP\/2 \u548c HTTP\/3 \u534f\u8bae\u5728<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc7540#section-7\">RFC 7540 \u7b2c 7 \u8282<\/a>\u548c<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9114.html#section-8.1\">RFC 9114 \u7b2c 8.1\u8282<\/a>\u4e2d\u5b9a\u4e49\u4e86\u534f\u8bae\u7ea7\u522b\u7684\u9519\u8bef\u4ee3\u7801\uff0c\u4f8b\u5982\uff0cHTTP\/2 \u4e2d\u7684REFUSED_STREAM\u00a0(0x7)\u00a0\u6216HTTP\/3 \u4e2d\u7684H3_EXCESSIVE_LOAD\u00a0(0x0107)\u00a0\u3002\u4e0e HTTP \u72b6\u6001\u4ee3\u7801\u4e0d\u540c\uff0c\u8fd9\u662f\u5bf9\u5927\u591a\u6570HttpClient\u7528\u6237\u6765\u8bf4\u4e0d\u91cd\u8981\u7684\u4f4e\u7ea7\u9519\u8bef\u4fe1\u606f\uff0c\u4f46\u5b83\u5728\u9ad8\u7ea7 HTTP\/2 \u6216 HTTP\/3 \u573a\u666f\u4e2d\u6709\u5e2e\u52a9\uff0c\u7279\u522b\u662f grpc-dotnet\uff0c\u5176\u4e2d\u533a\u5206\u534f\u8bae\u9519\u8bef\u5bf9\u4e8e\u5b9e\u73b0<a href=\"https:\/\/learn.microsoft.com\/aspnet\/core\/grpc\/retries?view=aspnetcore-7.0\">\u5ba2\u6237\u7aef\u91cd\u8bd5<\/a>\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p>\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b0\u7684\u5f02\u5e38<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.http.httpprotocolexception?view=net-7.0\">HttpProtocolException<\/a>\u6765\u5728\u5176ErrorCode\u5c5e\u6027\u4e2d\u4fdd\u5b58\u534f\u8bae\u7ea7\u9519\u8bef\u4ee3\u7801\u3002<\/p>\n<p>HttpClient\u76f4\u63a5\u8c03\u7528\u65f6\uff0cHttpProtocolException\u53ef\u4ee5\u662f\u5185\u90e8\u5f02\u5e38HttpRequestException\uff1a<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">try\r\n\r\n{\r\n\r\nusing var response = await httpClient.GetStringAsync(url);\r\n\r\n}\r\n\r\ncatch (HttpRequestException ex) when (ex.InnerException is HttpProtocolException pex)\r\n\r\n{\r\n\r\nConsole.WriteLine(\"HTTP error code: \" + pex.ErrorCode)\r\n\r\n}<\/code><\/pre>\n<p>\u4f7f\u7528HttpContent\u7684\u54cd\u5e94\u6d41\u65f6\uff0c\u5b83\u88ab\u76f4\u63a5\u629b\u51fa\uff1a<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">using var response = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);\r\n\r\nusing var responseStream = await response.Content.ReadAsStreamAsync();\r\n\r\ntry\r\n\r\n{\r\n\r\nawait responseStream.ReadAsync(buffer);\r\n\r\n}\r\n\r\ncatch (HttpProtocolException pex)\r\n\r\n{\r\n\r\nConsole.WriteLine(\"HTTP error code: \" + pex.ErrorCode)\r\n\r\n}<\/code><\/pre>\n<p><strong>HTTP\/3<\/strong><\/p>\n<p>\u5728HttpClient\u4e4b\u524d\u7684 .NET \u7248\u672c\u5df2\u7ecf\u5b8c\u6210\u4e86\u5bf9 HTTP\/3 \u7684\u652f\u6301\uff0c\u6240\u4ee5\u6211\u4eec\u4e3b\u8981\u96c6\u4e2d\u7cbe\u529b\u5728\u8fd9\u4e2a\u9886\u57df\u7684System.Net.Quic\u5e95\u5c42\u3002\u5c3d\u7ba1\u5982\u6b64\uff0c\u6211\u4eec\u786e\u5b9e\u5728 .NET 7 \u4e2d\u5f15\u5165\u4e86\u4e00\u4e9b\u4fee\u590d\u548c\u66f4\u6539\u3002<\/p>\n<p>\u6700\u91cd\u8981\u7684\u53d8\u5316\u662f\u73b0\u5728\u9ed8\u8ba4\u542f\u7528 HTTP\/3 (\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/73153\">dotnet\/runtime#73153<\/a>\u00a0)\u3002\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u4ece\u73b0\u5728\u5f00\u59cb\u6240\u6709 HTTP \u8bf7\u6c42\u90fd\u5c06\u9996\u9009 HTTP\/3\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u5b83\u4eec\u53ef\u80fd\u4f1a\u5347\u7ea7\u5230HTTP\/3\u3002\u4e3a\u6b64\uff0c\u8bf7\u6c42\u5fc5\u987b\u901a\u8fc7\u5c06<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.http.httprequestmessage.versionpolicy?view=net-7.0\">HttpRequestMessage.VersionPolicy<\/a>\u8bbe\u7f6e\u4e3aRequestVersionOrHigher\uff0c\u4ece\u800c\u80fd\u591f\u7248\u672c\u5347\u7ea7\u3002\u7136\u540e\uff0c\u5982\u679c\u670d\u52a1\u5668\u5728Alt-Svc header\u4e2d\u6709 HTTP\/3 \u6388\u6743\uff0cHttpClient\u5c06\u4f7f\u7528\u5b83\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u8bf7\u6c42\uff0c\u8bf7\u53c2\u9605<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9114#section-3.1.1\">RFC 9114 \u7b2c 3.1.1 \u8282<\/a>\u3002<\/p>\n<p>\u5217\u4e3e\u51e0\u4e2a\u5176\u4ed6\u6709\u8da3\u7684\u53d8\u5316\uff1a<\/p>\n<ul>\n<li>HTTP telemetry\u5df2\u6269\u5c55\u5230\u6db5\u76d6 HTTP\/3 \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/40896\">dotnet\/runtime#40896<\/a>\u3002<\/li>\n<li>\u5728\u65e0\u6cd5\u5efa\u7acb QUIC \u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u6539\u8fdb\u4e86\u5f02\u5e38\u8be6\u7ec6\u4fe1\u606f \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/70949\">dotnet\/runtime#70949<\/a>\u3002<\/li>\n<li>\u670d\u52a1\u5668\u540d\u79f0\u6807\u8bc6 (SNI) \u7684\u4e3bheader\u7684\u6b63\u786e\u4f7f\u7528\u5df2\u4fee\u590d \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/57169\">dotnet\/runtime#57169<\/a>\u3002<\/li>\n<\/ul>\n<p><strong>QUIC<\/strong><\/p>\n<p>QUIC \u662f\u4e00\u79cd\u65b0\u7684\u4f20\u8f93\u5c42\u534f\u8bae\u3002\u5b83\u6700\u8fd1\u5df2\u5728<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000\">RFC 9000<\/a>\u4e2d\u6807\u51c6\u5316\u3002\u5b83\u4f7f\u7528 UDP \u4f5c\u4e3a\u5e95\u5c42\u534f\u8bae\uff0c\u5e76\u4e14\u5b83\u672c\u8d28\u4e0a\u662f\u5b89\u5168\u7684\uff0c\u56e0\u4e3a\u5b83\u8981\u6c42\u4f7f\u7528 TLS 1.3\uff0c\u8bf7\u53c2\u9605<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9001\">RFC 9001<\/a>\u3002\u4e0e\u4f17\u6240\u5468\u77e5\u7684\u4f20\u8f93\u534f\u8bae\uff08\u5982 TCP \u548c UDP\uff09\u7684\u53e6\u4e00\u4e2a\u6709\u8da3\u533a\u522b\u662f\u5b83\u5728\u4f20\u8f93\u5c42\u4e0a\u5185\u7f6e\u4e86\u6d41\u591a\u8def\u590d\u7528\u3002\u8fd9\u4f7f\u5176\u80fd\u591f\u62e5\u6709\u591a\u4e2a\u5e76\u53d1\u7684\u72ec\u7acb\u6570\u636e\u6d41\uff0c\u4e14\u8fd9\u4e9b\u6570\u636e\u6d41\u4e0d\u4f1a\u76f8\u4e92\u5f71\u54cd\u3002<\/p>\n<p>QUIC \u672c\u8eab\u6ca1\u6709\u4e3a\u4ea4\u6362\u7684\u6570\u636e\u5b9a\u4e49\u4efb\u4f55\u8bed\u4e49\uff0c\u56e0\u4e3a\u5b83\u662f\u4e00\u79cd\u4f20\u8f93\u534f\u8bae\u3002\u5b83\u66f4\u9002\u7528\u4e8e\u5e94\u7528\u5c42\u534f\u8bae\uff0c\u4f8b\u5982<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9114\">HTTP\/3<\/a>\u6216<a href=\"https:\/\/learn.microsoft.com\/windows-server\/storage\/file-server\/smb-over-quic\">SMB over QUIC<\/a>\u3002\u5b83\u8fd8\u53ef\u4ee5\u7528\u4e8e\u4efb\u4f55\u81ea\u5b9a\u4e49\u534f\u8bae\u3002<\/p>\n<p>\u4e0e TLS \u7684 TCP \u76f8\u6bd4\uff0c\u8be5\u534f\u8bae\u5177\u6709\u8bb8\u591a\u4f18\u52bf\u3002\u4f8b\u5982\uff0c\u5b83\u4e0d\u9700\u8981\u50cf\u9876\u90e8\u5e26\u6709 TLS \u7684 TCP \u90a3\u6837\u591a\u7684\u5f80\u8fd4\u884c\u7a0b\uff0c\u6240\u4ee5\u80fd\u591f\u66f4\u5feb\u5730\u5efa\u7acb\u8fde\u63a5\u3002\u5b83\u80fd\u591f\u907f\u514d\u961f\u5934\u963b\u585e\u95ee\u9898\uff0c\u4e00\u4e2a\u4e22\u5931\u7684\u6570\u636e\u5305\u4e0d\u4f1a\u963b\u585e\u6240\u6709\u5176\u4ed6\u6d41\u7684\u6570\u636e\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u4f7f\u7528 QUIC \u4e5f\u6709\u7f3a\u70b9\u3002\u7531\u4e8e\u5b83\u662f\u4e00\u4e2a\u65b0\u534f\u8bae\uff0c\u5b83\u7684\u91c7\u7528\u4ecd\u5728\u589e\u957f\u5e76\u4e14\u662f\u6709\u9650\u7684\u3002\u9664\u6b64\u4e4b\u5916\uff0cQUIC \u6d41\u91cf\u751a\u81f3\u53ef\u80fd\u88ab\u67d0\u4e9b\u7f51\u7edc\u7ec4\u4ef6\u963b\u6b62\u3002<\/p>\n<h3>.NET \u4e2d\u7684 QUIC<\/h3>\n<p>\u6211\u4eec\u5728System.Net.Quic\u5e93\u4e2d\u4ecb\u7ecd\u4e86 .NET 5 \u4e2d\u7684 QUIC \u5b9e\u73b0\u3002\u7136\u800c\uff0c\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u8fd9\u4e2a\u5e93\u662f\u4ec5\u9650\u5185\u90e8\u7684\uff0c\u5e76\u4e14\u53ea\u4e3a\u81ea\u5df1\u7684 HTTP\/3 \u5b9e\u73b0\u670d\u52a1\u3002\u968f\u7740 .NET 7 \u7684\u53d1\u5e03\uff0c\u6211\u4eec\u516c\u5f00\u4e86\u8be5\u5e93\u5e76\u516c\u5f00\u4e86\u5b83\u7684 API\u3002\u7531\u4e8e\u6211\u4eec\u53ea\u6709HttpClient\u548cKestrel \u4f5c\u4e3a\u6b64\u7248\u672c API \u7684\u4f7f\u7528\u8005\uff0c\u56e0\u6b64\u6211\u4eec\u51b3\u5b9a\u5c06\u5b83\u4eec\u4fdd\u7559\u4e3a<a href=\"https:\/\/github.com\/dotnet\/designs\/blob\/main\/accepted\/2021\/preview-features\/preview-features.md\">\u9884\u89c8\u529f\u80fd<\/a>\u3002\u5b83\u4f7f\u6211\u4eec\u80fd\u591f\u5728\u786e\u5b9a\u6700\u7ec8\u5f62\u5f0f\u4e4b\u524d\u5728\u4e0b\u4e00\u4e2a\u7248\u672c\u4e2d\u8c03\u6574 API\u3002<\/p>\n<p>\u4ece\u5b9e\u65bd\u7684\u89d2\u5ea6\u6765\u770b\uff0cSystem.Net.Quic\u53d6\u51b3\u4e8eQUIC \u534f\u8bae\u7684\u539f\u751f\u5b9e\u73b0<a href=\"https:\/\/github.com\/microsoft\/msquic\">MsQuic<\/a>\u3002\u56e0\u6b64\uff0cSystem.Net.Quic\u5e73\u53f0\u652f\u6301\u548c\u4f9d\u8d56\u9879\u7ee7\u627f\u81ea MsQuic\uff0c\u5e76\u8bb0\u5f55\u5728<u><a href=\"https:\/\/learn.microsoft.com\/dotnet\/core\/extensions\/httpclient-http3#platform-dependencies\">HTTP\/3 \u5e73\u53f0\u4f9d\u8d56\u9879<\/a><\/u>\u6587\u6863\u4e2d\u3002\u7b80\u800c\u8a00\u4e4b\uff0cMsQuic \u5e93\u4f5c\u4e3a .NET for Windows \u7684\u4e00\u90e8\u5206\u63d0\u4f9b\u3002\u5bf9\u4e8e Linux\uff0clibmsquic\u5fc5\u987b\u901a\u8fc7\u9002\u5f53\u7684\u5305\u7ba1\u7406\u5668\u624b\u52a8\u5b89\u88c5\u3002\u5bf9\u4e8e\u5176\u4ed6\u5e73\u53f0\uff0c\u4ecd\u7136\u53ef\u4ee5\u624b\u52a8\u6784\u5efa MsQuic\uff0c\u65e0\u8bba\u662f\u9488\u5bf9 SChannel \u8fd8\u662f OpenSSL\uff0c\u5e76\u5c06\u5176\u4e0eSystem.Net.Quic\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<h3>API \u6982\u8ff0<\/h3>\n<p><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic?view=net-7.0\">System.Net.Quic<\/a>\u00a0\u643a\u5e26\u4e86\u80fd\u591f\u4f7f\u7528QUIC\u534f\u8bae\u7684\u4e09\u4e2a\u4e3b\u8981\u7c7b:<\/p>\n<ul>\n<li>QuicListener\u00a0\u2013 -\u670d\u52a1\u5668\u7aef\u7c7b\uff0c\u7528\u4e8e\u63a5\u53d7\u4f20\u5165\u8fde\u63a5\u3002<\/li>\n<li>QuicConnection\u00a0\u2013 QUIC\u8fde\u63a5\uff0c\u5bf9\u5e94<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-5\">RFC 9000 Section 5<\/a>.<\/li>\n<li>QuicStream\u00a0\u2013 QUIC\u6d41\uff0c\u5bf9\u5e94<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-2\">RFC 9000 Section 2<\/a>.<\/li>\n<\/ul>\n<p>\u4f46\u662f\u5728\u4f7f\u7528\u8fd9\u4e9b\u7c7b\u4e4b\u524d\uff0c\u7528\u6237\u4ee3\u7801\u5e94\u8be5\u68c0\u67e5\u5f53\u524d\u7cfb\u7edf\u662f\u5426\u652f\u6301QUIC\uff0c\u56e0\u4e3a\u7cfb\u7edf\u53ef\u80fd\u7f3a\u5931libmsquic\u00a0\u6216\u8005\u4e0d\u652f\u6301TLS 1.3\u3002\u4e3a\u6b64,\u00a0QuicListener\u548cQuicConnection\u90fd\u516c\u5f00\u4e86\u4e00\u4e2a\u9759\u6001\u5c5e\u6027IsSupported:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">if (QuicListener.IsSupported)\r\n{\r\n    \/\/ Use QuicListener\r\n}\r\nelse\r\n{\r\n    \/\/ Fallback\/Error\r\n}\r\n\r\nif (QuicConnection.IsSupported)\r\n{\r\n    \/\/ Use QuicConnection\r\n}\r\nelse\r\n{\r\n    \/\/ Fallback\/Error\r\n}<\/code><\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u76ee\u524d\u8fd9\u4e24\u4e2a\u5c5e\u6027\u662f\u540c\u6b65\u7684\u5e76\u5c06\u663e\u793a\u76f8\u540c\u7684\u503c\uff0c\u4f46\u5c06\u6765\u53ef\u80fd\u4f1a\u6539\u53d8\u3002\u6240\u4ee5\u6211\u4eec\u5efa\u8bae\u68c0\u67e5\u4e00\u4e0b\u652f\u6301\u670d\u52a1\u5668\u573a\u666f\u7684<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quiclistener.issupported?view=net-7.0\">QuicListener.IsSupported<\/a>\u548c\u7528\u4e8e\u5ba2\u6237\u7aef\u7684<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quiclistener.issupported?view=net-7.0\">QuicListener.IsSupported<\/a>\u3002<\/p>\n<h3>QuicListener<\/h3>\n<p><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quiclistener?view=net-7.0\">QuicListener<\/a>\u00a0\u5c5e\u4e8e\u63a5\u53d7\u5ba2\u6237\u7aef\u7684\u4f20\u5165\u8fde\u63a5\u7684\u670d\u52a1\u5668\u7aef\u7c7b\u3002 \u8be5\u4fa6\u542c\u8bbe\u5907\u662f\u901a\u8fc7\u9759\u6001\u65b9\u6cd5<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quiclistener.listenasync?view=net-7.0\">QuicListener.ListenAsync<\/a>\u6784\u9020\u548c\u542f\u52a8\u7684\u3002\u8be5\u65b9\u6cd5\u63a5\u53d7<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quiclisteneroptions?view=net-7.0\">QuicListenerOptions<\/a>\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u5176\u4e2d\u5305\u542b\u542f\u52a8\u4fa6\u542c\u8bbe\u5907\u548c\u63a5\u53d7\u4f20\u5165\u8fde\u63a5\u6240\u9700\u7684\u6240\u6709\u8bbe\u7f6e\u3002\u4e4b\u540e\uff0c\u4fa6\u542c\u8bbe\u5907\u7740\u624b\u901a\u8fc7<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quiclistener.acceptconnectionasync?view=net-7.0\">AcceptConnectionAsync<\/a>\u5206\u53d1\u8fde\u63a5\u3002\u6b64\u65b9\u6cd5\u8fd4\u56de\u7684\u8fde\u63a5\u59cb\u7ec8\u662f\u5b8c\u5168\u8fde\u63a5\u7684\uff0c\u8fd9\u610f\u5473\u7740TLS\u4ea4\u4e92\u5df2\u7ecf\u5b8c\u6210\uff0c\u8fde\u63a5\u53ef\u4ee5\u4f7f\u7528\u4e86\u3002\u6700\u540e\uff0c\u8981\u5173\u95ed\u4fa6\u542c\u8bbe\u5907\u5e76\u91ca\u653e\u6240\u6709\u8d44\u6e90\uff0c\u5fc5\u987b\u8c03\u7528<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quiclistener.disposeasync?view=net-7.0\">DisposeAsync<\/a>\u00a0\u65b9\u6cd5\u3002<\/p>\n<p>QuicListener\u7684\u793a\u4f8b\u7528\u6cd5\uff1a<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">using System.Net.Quic;\r\n\r\n\/\/ First, check if QUIC is supported.\r\nif (!QuicListener.IsSupported)\r\n{\r\n    Console.WriteLine(\"QUIC is not supported, check for presence of libmsquic and support of TLS 1.3.\");\r\n    return;\r\n}\r\n\r\n\/\/ We want the same configuration for each incoming connection, so we prepare the connection options upfront and reuse them.\r\n\/\/ This represents the minimal configuration necessary.\r\nvar serverConnectionOptions = new QuicServerConnectionOptions()\r\n{\r\n    \/\/ Used to abort stream if it's not properly closed by the user.\r\n    \/\/ See https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-20.2\r\n    DefaultStreamErrorCode = 0x0A, \/\/ Protocol-dependent error code.\r\n\r\n    \/\/ Used to close the connection if it's not done by the user.\r\n    \/\/ See https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-20.2\r\n    DefaultCloseErrorCode = 0x0B, \/\/ Protocol-dependent error code.\r\n\r\n    \/\/ Same options as for server side SslStream.\r\n    ServerAuthenticationOptions = new SslServerAuthenticationOptions\r\n    {\r\n        \/\/ List of supported application protocols, must be the same or subset of QuicListenerOptions.ApplicationProtocols.\r\n        ApplicationProtocols = new List&lt;SslApplicationProtocol&gt;() { \"protocol-name\" },\r\n        \/\/ Server certificate, it can also be provided via ServerCertificateContext or ServerCertificateSelectionCallback.\r\n        ServerCertificate = serverCertificate\r\n    }\r\n};\r\n\r\n\/\/ Initialize, configure the listener and start listening.\r\nvar listener = await QuicListener.ListenAsync(new QuicListenerOptions()\r\n{\r\n    \/\/ Listening endpoint, port 0 means any port.\r\n    ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),\r\n    \/\/ List of all supported application protocols by this listener.\r\n    ApplicationProtocols = new List&lt;SslApplicationProtocol&gt;() { \"protocol-name\" },\r\n    \/\/ Callback to provide options for the incoming connections, it gets called once per each connection.\r\n    ConnectionOptionsCallback = (_, _, _) =&gt; ValueTask.FromResult(serverConnectionOptions)\r\n});\r\n\r\n\/\/ Accept and process the connections.\r\nwhile (isRunning)\r\n{\r\n    \/\/ Accept will propagate any exceptions that occurred during the connection establishment,\r\n    \/\/ including exceptions thrown from ConnectionOptionsCallback, caused by invalid QuicServerConnectionOptions or TLS handshake failures.\r\n    var connection = await listener.AcceptConnectionAsync();\r\n\r\n    \/\/ Process the connection...\r\n}\r\n\r\n\/\/ When finished, dispose the listener.\r\nawait listener.DisposeAsync();<\/code><\/pre>\n<p>\u66f4\u591a\u5173\u4e8e\u8fd9\u4e2a\u7c7b\u8bbe\u8ba1\u7684\u7ec6\u8282\u53ef\u4ee5\u5728QuicListener API Proposal (<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/67560\">dotnet\/runtime#67560<\/a>) \u4e2d\u627e\u5230\u3002<\/p>\n<h3>QuicConnection<\/h3>\n<p>\u662f\u7528\u4e8e\u670d\u52a1\u5668\u7aef\u548c\u5ba2\u6237\u7aefQUIC\u8fde\u63a5\u7684\u7c7b\u3002\u670d\u52a1\u5668\u7aef\u8fde\u63a5\u7531\u4fa6\u542c\u8bbe\u5907\u5185\u90e8\u521b\u5efa\uff0c\u5e76\u901a\u8fc7QuicListener.AcceptConnectionAsync\u5206\u53d1\u8fde\u63a5\u3002\u5ba2\u6237\u7aef\u8fde\u63a5\u5fc5\u987b\u88ab\u6253\u5f00\u5e76\u8fde\u63a5\u5230\u670d\u52a1\u5668\u3002\u9759\u6001\u65b9\u6cd5QuicConnection\u548c\u4fa6\u542c\u8bbe\u5907\u4e00\u8d77\uff0c\u5efa\u7acb\u5e76\u5b9e\u4f8b\u8fde\u63a5\u3002\u5b83\u63a5\u53d7QuicClientConnectionOptions\u7684\u5b9e\u4f8b\uff0c\u8fd9\u662f\u4e00\u4e2a\u7c7b\u4f3c\u4e8eQuicServerConnectionOptions\u7684\u7c7b\u3002\u521d\u6b21\u4e4b\u524d\uff0c\u6b64\u94fe\u63a5\u7684\u5de5\u4f5c\u65b9\u5f0f\u4e0e\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u6ca1\u6709\u533a\u522b\u3002\u5b83\u53ef\u4ee5\u6253\u5f00\u5411\u5916\u548c\u5411\u5185\u7684\u6d41\u3002\u5b83\u8fd8\u63d0\u4f9b\u4e0e\u8fde\u63a5\u4fe1\u606f\u6709\u5173\u7684\u5c5e\u6027\uff0c\u5982LocalEndPoint\u3001RemoteEndPoint\u6216RemoteCertificate\u3002<\/p>\n<p>\u5f53\u8fde\u63a5\u7684\u5de5\u4f5c\u5b8c\u6210\u540e\uff0c\u9700\u8981\u5173\u95ed\u548c\u5904\u7f6e\u4fa6\u542c\u8bbe\u5907\u3002QUIC\u534f\u8bae\u8981\u6c42\u4f7f\u7528\u5e94\u7528\u5c42\u4ee3\u7801\u7acb\u5373\u5173\u95ed\u4fa6\u542c\u8bbe\u5907\uff0c\u53c2\u89c1<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-10.2\">RFC 9000 Section 10.2<\/a>\u3002\u4e3a\u6b64\uff0c\u53ef\u4ee5\u8c03\u7528\u5e26\u6709\u5e94\u7528\u5c42\u4ee3\u7801\u7684<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicconnection.closeasync?view=net-7.0\">CloseAsync<\/a>\u00a0\uff0c\u5982\u679c\u6ca1\u6709\uff0c<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicconnection.disposeasync?view=net-7.0\">DisposeAsync<\/a>\u5c06\u4f7f\u7528<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicconnectionoptions.defaultcloseerrorcode?view=net-7.0#system-net-quic-quicconnectionoptions-defaultcloseerrorcode\">QuicConnectionOptions.DefaultCloseErrorCode<\/a>\u4e2d\u63d0\u4f9b\u7684\u4ee3\u7801\u3002\u65e0\u8bba\u662f\u54ea\u79cd\u65b9\u5f0f\uff0c\u90fd\u5fc5\u987b\u5728\u8fde\u63a5\u5de5\u4f5c\u7ed3\u675f\u65f6\u8c03\u7528<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicconnection.disposeasync?view=net-7.0\">DisposeAsync<\/a>\uff0c\u6d8c\u8d77\u5b8c\u5168\u91ca\u653e\u6240\u6709\u76f8\u5173\u8d44\u6e90\u3002<\/p>\n<p>QuicConnection\u7684\u793a\u4f8b\u7528\u6cd5:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">using System.Net.Quic;\r\n\r\n\/\/ First, check if QUIC is supported.\r\nif (!QuicConnection.IsSupported)\r\n{\r\n    Console.WriteLine(\"QUIC is not supported, check for presence of libmsquic and support of TLS 1.3.\");\r\n    return;\r\n}\r\n\r\n\/\/ This represents the minimal configuration necessary to open a connection.\r\nvar clientConnectionOptions = new QuicClientConnectionOptions()\r\n{\r\n    \/\/ End point of the server to connect to.\r\n    RemoteEndPoint = listener.LocalEndPoint,\r\n\r\n    \/\/ Used to abort stream if it's not properly closed by the user.\r\n    \/\/ See https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-20.2\r\n    DefaultStreamErrorCode = 0x0A, \/\/ Protocol-dependent error code.\r\n\r\n    \/\/ Used to close the connection if it's not done by the user.\r\n    \/\/ See https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-20.2\r\n    DefaultCloseErrorCode = 0x0B, \/\/ Protocol-dependent error code.\r\n\r\n    \/\/ Optionally set limits for inbound streams.\r\n    MaxInboundUnidirectionalStreams = 10,\r\n    MaxInboundBidirectionalStreams = 100,\r\n\r\n    \/\/ Same options as for client side SslStream.\r\n    ClientAuthenticationOptions = new SslClientAuthenticationOptions()\r\n    {\r\n        \/\/ List of supported application protocols.\r\n        ApplicationProtocols = new List&lt;SslApplicationProtocol&gt;() { \"protocol-name\" }\r\n    }\r\n};\r\n\r\n\/\/ Initialize, configure and connect to the server.\r\nvar connection = await QuicConnection.ConnectAsync(clientConnectionOptions);\r\n\r\nConsole.WriteLine($\"Connected {connection.LocalEndPoint} --&gt; {connection.RemoteEndPoint}\");\r\n\r\n\/\/ Open a bidirectional (can both read and write) outbound stream.\r\nvar outgoingStream = await connection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional);\r\n\r\n\/\/ Work with the outgoing stream ...\r\n\r\n\/\/ To accept any stream on a client connection, at least one of MaxInboundBidirectionalStreams or MaxInboundUnidirectionalStreams of QuicConnectionOptions must be set.\r\nwhile (isRunning)\r\n{\r\n    \/\/ Accept an inbound stream.\r\n    var incomingStream = await connection.AcceptInboundStreamAsync();\r\n\r\n    \/\/ Work with the incoming stream ...\r\n}\r\n\r\n\/\/ Close the connection with the custom code.\r\nawait connection.CloseAsync(0x0C);\r\n\r\n\/\/ Dispose the connection.\r\nawait connection.DisposeAsync();<\/code><\/pre>\n<p>\u66f4\u591a\u5173\u4e8e\u8fd9\u4e2a\u7c7b\u8bbe\u8ba1\u7684\u7ec6\u8282\u53ef\u4ee5\u5728QuicConnection\u00a0API Proposal (<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/68902\">dotnet\/runtime#68902<\/a>) \u4e2d\u627e\u5230\u3002<\/p>\n<h3>QuicStream<\/h3>\n<p><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicstream?view=net-7.0\">QuicStream<\/a>\u662fQUIC\u534f\u8bae\u4e2d\u7528\u4e8e\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e\u7684\u5b9e\u9645\u7c7b\u578b\u3002\u5b83\u8d77\u6e90\u4e8e\u666e\u901a\u7684\u6d41<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.io.stream?view=net-7.0\">Stream<\/a>\u3002\u53ef\u4ee5\u548c\u666e\u901a\u7684\u6d41\u4e00\u6837\u4f7f\u7528\uff0c\u4f46\u5b83\u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7279\u5b9a\u4e8eQUIC\u534f\u8bae\u7684\u7279\u6027\u3002\u9996\u5148\uff0cQUIC\u6d41\u53ef\u4ee5\u662f\u5355\u5411\u7684\uff0c\u4e5f\u53ef\u4ee5\u662f\u53cc\u5411\u7684\uff0c\u53c2\u89c1<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-2.1\">RFC 9000 Section 2.1<\/a>\u3002\u53cc\u5411\u6d41\u80fd\u591f\u5728\u4e24\u7aef\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e\uff0c\u800c\u5355\u5411\u6d41\u53ea\u80fd\u4ece\u53d1\u8d77\u7aef\u8f93\u5165\u6570\u636e\uff0c\u4ece\u63a5\u53d7\u7aef\u8bfb\u53d6\u3002\u6bcf\u7aef\u90fd\u53ef\u4ee5\u9650\u5236\u6bcf\u79cd\u7c7b\u578b\u7684\u5e76\u53d1\u6d41\u7684\u6570\u91cf\uff0c\u53c2\u89c1<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicconnectionoptions.maxinboundbidirectionalstreams?view=net-7.0\">QuicConnectionOptions.MaxInboundBidirectionalStreams<\/a>\u00a0\u4e0e\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicconnectionoptions.maxinboundunidirectionalstreams?view=net-7.0\">QuicConnectionOptions.MaxInboundUnidirectionalStreams<\/a>.<\/p>\n<p>QUIC\u6d41\u7684\u53e6\u4e00\u4e2a\u7279\u70b9\u662f\u80fd\u591f\u5728\u6d41\u7684\u5de5\u4f5c\u8fc7\u7a0b\u4e2d\u663e\u5f0f\u5730\u5173\u95ed\u5199\u5165\u7aef\uff0c\u53c2\u89c1<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicstream.completewrites?view=net-7.0\">CompleteWrites<\/a>\u00a0or\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicstream.writeasync?view=net-7.0#system-net-quic-quicstream-writeasync(system-readonlymemory((system-byte)\">WriteAsync<\/a>-system-boolean-system-threading-cancellationtoken))\u91cd\u8f7dCompleteWrites\u53c2\u6570\u3002\u5173\u95ed\u5199\u5165\u7aef\u53ef\u4ee5\u8ba9\u63a5\u53d7\u7aef\u660e\u786e\u4e0d\u4f1a\u518d\u6709\u66f4\u591a\u7684\u6570\u636e\u8f93\u5165\u4e86\uff0c\u4f46\u53e6\u4e00\u7aef\u4ecd\u7136\u53ef\u4ee5\u7ee7\u7eed\u53d1\u9001\u6570\u636e\u6d41(\u5728\u53cc\u5411\u6d41\u7684\u60c5\u51b5\u4e0b)\u3002\u8fd9\u5728HTTP\u8bf7\u6c42\/\u54cd\u5e94\u4ea4\u6362\u7b49\u573a\u666f\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u5e76\u5173\u95ed\u5199\u5165\u7aef\uff0c\u670d\u52a1\u5668\u5c31\u77e5\u9053\u8fd9\u662f\u8bf7\u6c42\u53d1\u9001\u7684\u6240\u6709\u5185\u5bb9\u4e86\u3002\u5728\u6b64\u4e4b\u540e\uff0c\u670d\u52a1\u5668\u4ecd\u7136\u80fd\u591f\u53d1\u9001\u54cd\u5e94\uff0c\u4f46\u5ba2\u6237\u7aef\u5374\u4e0d\u4f1a\u53d1\u9001\u66f4\u591a\u7684\u6570\u636e\u6d41\u4e86\u3002\u800c\u5bf9\u4e8e\u9519\u8bef\u7684\u60c5\u51b5\uff0c\u6d41\u7684\u5199\u5165\u6216\u8bfb\u53d6\u7aef\u90fd\u53ef\u4ee5\u8fdb\u884c\u4e2d\u6b62\uff0c\u8bf7\u53c2\u9605<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.quic.quicstream.abort?view=net-7.0\">Abort<\/a>\u3002\u4e0b\u8868\u603b\u7ed3\u4e86\u6bcf\u79cd\u6d41\u7c7b\u578b\u7684\u6bcf\u79cd\u65b9\u6cd5\u7684\u8868\u73b0(\u6ce8\u610f\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u90fd\u53ef\u4ee5\u5f00\u653e\u548c\u63a5\u53d7\u6d41):<\/p>\n<table>\n<thead>\n<tr>\n<td><\/td>\n<th scope=\"col\">Peer opening stream<\/th>\n<th scope=\"col\">Peer accepting stream<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th scope=\"row\">CanRead<\/th>\n<td><em>bidirectional<\/em>:\u00a0true\u00a0<em>unidirectional<\/em>:\u00a0false<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">CanWrite<\/th>\n<td>true<\/td>\n<td><em>bidirectional<\/em>:\u00a0true\u00a0<em>unidirectional<\/em>:\u00a0false<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">ReadAsync<\/th>\n<td><em>bidirectional<\/em>: reads data\u00a0<em>unidirectional<\/em>:\u00a0InvalidOperationException<\/td>\n<td>reads data<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">WriteAsync<\/th>\n<td>sends data =&gt; peer read returns the data<\/td>\n<td><em>bidirectional<\/em>: sends data =&gt; peer read returns the data\u00a0<em>unidirectional<\/em>:\u00a0InvalidOperationException<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">CompleteWrites<\/th>\n<td>closes writing side =&gt; peer read returns 0<\/td>\n<td><em>bidirectional<\/em>: closes writing side =&gt; peer read returns 0\u00a0<em>unidirectional<\/em>: no-op<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">Abort(QuicAbortDirection.Read)<\/th>\n<td><em>bidirectional<\/em>:\u00a0<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-19.5\">STOP_SENDING<\/a>\u00a0=&gt; peer write throws\u00a0QuicException(QuicError.OperationAborted)\u00a0<em>unidirectional<\/em>: no-op<\/td>\n<td><a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-19.5\">STOP_SENDING<\/a>\u00a0=&gt; peer write throws\u00a0QuicException(QuicError.OperationAborted)<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">Abort(QuicAbortDirection.Write)<\/th>\n<td><a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-19.4\">RESET_STREAM<\/a>\u00a0=&gt; peer read throws\u00a0QuicException(QuicError.OperationAborted)<\/td>\n<td><em>bidirectional<\/em>:\u00a0<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9000#section-19.4\">RESET_STREAM<\/a>\u00a0=&gt; peer read throws\u00a0QuicException(QuicError.OperationAborted)\u00a0<em>unidirectional<\/em>: no-op<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5728\u4ee5\u4e0a\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0cquickstream\u63d0\u4f9b\u4e86\u4e24\u4e2a\u4e13\u95e8\u7684\u5c5e\u6027\uff0c\u7528\u4e8e\u5728\u6d41\u7684\u8bfb\u5199\u7aef\u5173\u95ed\u65f6\u83b7\u5f97\u901a\u77e5:\u5b83\u4eec\u662freadclosed\u548cWritesClosed\u3002\u4e24\u8005\u90fd\u8fd4\u56de\u4e00\u4e2a\u4efb\u52a1\uff0c\u8be5\u4efb\u52a1\u5b8c\u6210\u540e\u76f8\u5e94\u7684\u8fb9\u88ab\u5173\u95ed\u3002\u65e0\u8bba\u4efb\u52a1\u662f\u6210\u529f\u8fd8\u662f\u4e2d\u6b62\uff0c\u5176\u4e2d\u90fd\u5c06\u5305\u542b\u76f8\u5e94\u7684\u5b57\u6bb5\u3002\u5f53\u7528\u6237\u4ee3\u7801\u9700\u8981\u77e5\u9053\u6d41\u7aef\u7684\u5173\u95ed\u60c5\u51b5\u800c\u4e0d\u9700\u8981\u8c03\u7528ReadAsync\u6216WriteAsync\u65f6\uff0c\u8fd9\u4e9b\u5c5e\u6027\u975e\u5e38\u5c31\u6d3e\u4e0a\u4f5c\u7528\u4e86\u3002<\/p>\n<p>\u6700\u540e\uff0c\u5f53\u6d41\u7684\u5de5\u4f5c\u5b8c\u6210\u65f6\uff0c\u5b83\u9700\u8981\u4f7f\u7528DisposeAsync\u65b9\u6cd5\u3002\u8fd9\u4e00\u65b9\u6cd5\u5c06\u786e\u4fdd\u8bfb\u53d6\/\u5199\u5165\u7aef(\u53d6\u51b3\u4e8e\u6d41\u7c7b\u578b)\u90fd\u5173\u95ed\u3002\u5982\u679c\u6d41\u76f4\u5230\u7ed3\u675f\u8fd8\u6ca1\u6709\u88ab\u6b63\u786e\u8bfb\u53d6\uff0cdispose\u5c06\u53d1\u51fa\u4e00\u4e2a\u7b49\u6548\u7684Abort(QuicAbortDirection.Read)\u547d\u4ee4\u3002\u4f46\u662f\uff0c\u5982\u679c\u6d41\u5199\u5165\u7aef\u8fd8\u6ca1\u6709\u5173\u95ed\uff0c\u5199\u5165\u7aef\u4f1a\u50cf\u4f7f\u7528CompleteWrites\u65b9\u6cd5\u4e00\u6837\u88ab\u5173\u95ed\u3002\u4e4b\u6240\u4ee5\u5b58\u5728\u8fd9\u79cd\u5dee\u5f02\uff0c\u662f\u4e3a\u4e86\u786e\u4fdd\u666e\u901a\u6d41\u7684\u4f7f\u7528\u80fd\u591f\u6309\u7167\u9884\u671f\u7684\u65b9\u5f0f\u8fdb\u884c\uff0c\u5e76\u8fdb\u5165\u76f8\u5e94\u7684\u8def\u5f84\u3002\u8bf7\u53c2\u8003\u4ee5\u4e0b\u4f8b\u5b50:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">\/\/ Work done with all different types of streams.\r\nasync Task WorkWithStream(Stream stream)\r\n{\r\n    \/\/ This will dispose the stream at the end of the scope.\r\n    await using (stream)\r\n    {\r\n        \/\/ Simple echo, read data and send them back.\r\n        byte[] buffer = new byte[1024];\r\n        int count = 0;\r\n        \/\/ The loop stops when read returns 0 bytes as is common for all streams.\r\n        while ((count = await stream.ReadAsync(buffer)) &gt; 0)\r\n        {\r\n            await stream.WriteAsync(buffer.AsMemory(0, count));\r\n        }\r\n    }\r\n}\r\n\r\n\/\/ Open a QuicStream and pass to the common method.\r\nvar quicStream = await connection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional);\r\nawait WorkWithStream(quicStream);<\/code><\/pre>\n<p>\u5ba2\u6237\u7aef\u573a\u666f\u4e0bQuicStream\u7684\u4f7f\u7528\u793a\u4f8b:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">\/\/ Consider connection from the connection example, open a bidirectional stream.\r\nawait using var stream = await connection.OpenStreamAsync(QuicStreamType.Bidirectional, cancellationToken);\r\n\r\n\/\/ Send some data.\r\nawait stream.WriteAsync(data, cancellationToken);\r\nawait stream.WriteAsync(data, cancellationToken);\r\n\r\n\/\/ End the writing-side together with the last data.\r\nawait stream.WriteAsync(data, endStream: true, cancellationToken);\r\n\/\/ Or separately.\r\nstream.CompleteWrites();\r\n\r\n\/\/ Read data until the end of stream.\r\nwhile (await stream.ReadAsync(buffer, cancellationToken) &gt; 0)\r\n{\r\n    \/\/ Handle buffer data...\r\n}\r\n\r\n\/\/ DisposeAsync called by await using at the top<\/code><\/pre>\n<p>\u670d\u52a1\u7aef\u573a\u666f\u4e0bQuicStream\u7684\u4f7f\u7528\u793a\u4f8b:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">\/\/ Consider connection from the connection example, accept a stream.\r\nawait using var stream = await connection.AcceptStreamAsync(cancellationToken);\r\n\r\nif (stream.Type != QuicStreamType.Bidirectional)\r\n{\r\n    Console.WriteLine($\"Expected bidirectional stream, got {stream.Type}\");\r\n    return;\r\n}\r\n\r\n\/\/ Read the data.\r\nwhile (stream.ReadAsync(buffer, cancellationToken) &gt; 0)\r\n{\r\n    \/\/ Handle buffer data...\r\n\r\n    \/\/ Client completed the writes, the loop might be exited now without another ReadAsync.\r\n    if (stream.ReadsCompleted.IsCompleted)\r\n    {\r\n        break;\r\n    }\r\n}\r\n\r\n\/\/ Listen for Abort(QuicAbortDirection.Read) from the client.\r\nvar writesClosedTask = WritesClosedAsync(stream);\r\nasync ValueTask WritesClosedAsync(QuicStream stream)\r\n{\r\n    try\r\n    {\r\n        await stream.WritesClosed;\r\n    }\r\n    catch (Exception ex)\r\n    {\r\n        \/\/ Handle peer aborting our writing side ...\r\n    }\r\n}\r\n\r\n\/\/ DisposeAsync called by await using at the top.<\/code><\/pre>\n<p>\u66f4\u591a\u5173\u4e8e\u8fd9\u4e2a\u7c7b\u8bbe\u8ba1\u7684\u7ec6\u8282\u53ef\u4ee5\u5728the\u00a0QuicStream\u00a0API Proposal (<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/69675\">dotnet\/runtime#69675<\/a>)\u4e2d\u627e\u5230\u3002<\/p>\n<h3 lang=\"zh-CN\">\u672a\u6765<\/h3>\n<p>\u7531\u4e8eSystem.Net.Quic\u00a0\u662f\u65b0\u516c\u5f00\u7684\uff0c\u5e76\u4e14\u7528\u6cd5\u6709\u9650\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u4e0d\u80dc\u611f\u6fc0\u6709\u5173API\u5f62\u72b6\u7684\u4efb\u4f55\u9519\u8bef\u62a5\u544a\u6216\u89c1\u89e3\u3002\u7531\u4e8e API \u5904\u4e8e\u9884\u89c8\u6a21\u5f0f\uff0c\u6211\u4eec\u4ecd\u7136\u6709\u673a\u4f1a\u6839\u636e\u6536\u5230\u7684\u53cd\u9988\u9488\u5bf9 .NET 8 \u8c03\u6574\u5b83\u4eec\u3002\u53ef\u4ee5\u5728 <a href=\"https:\/\/github.com\/dotnet\/runtime\">dotnet\/runtime<\/a>\u00a0\u5b58\u50a8\u5e93\u4e2d\u63d0\u4ea4\u95ee\u9898\u3002<\/p>\n<h3 lang=\"zh-CN\">\u5b89\u5168<\/h3>\n<h3>Negotiate API<\/h3>\n<p><a href=\"https:\/\/learn.microsoft.com\/windows-server\/security\/windows-authentication\/windows-authentication-overview\">Windows Authentication<\/a>\u00a0\u662f\u4e00\u4e2a\u5305\u542b\u591a\u79cd\u6280\u672f\u7684\u672f\u8bed\uff0c\u7528\u4e8e\u4f01\u4e1a\u4e2d\u9488\u5bf9\u4e2d\u592e\u673a\u6784\uff08\u901a\u5e38\u662f\u57df\u63a7\u5236\u5668\uff09\u5bf9\u7528\u6237\u548c\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3002\u5b83\u652f\u6301\u8bf8\u5982\u5355\u70b9\u767b\u5f55\u7535\u5b50\u90ae\u4ef6\u670d\u52a1\u6216 Intranet \u5e94\u7528\u7a0b\u5e8f\u4e4b\u7c7b\u7684\u573a\u666f\u3002\u7528\u4e8e\u8eab\u4efd\u9a8c\u8bc1\u7684\u57fa\u7840\u6280\u672f\u662f Kerberos\u3001NTLM \u548c\u5305\u542b\u7684Negotiate\u534f\u8bae\uff0c\u5176\u4e2d\u4e3a\u7279\u5b9a\u8eab\u4efd\u9a8c\u8bc1\u65b9\u6848\u9009\u62e9\u6700\u5408\u9002\u7684\u6280\u672f\u3002<\/p>\n<p>\u5728 .NET 7 \u4e4b\u524d\uff0cWindows \u8eab\u4efd\u9a8c\u8bc1\u5728\u9ad8\u7ea7 API \u4e2d\u516c\u5f00\u3002\u4f8b\u5982HttpClient\u00a0(Negotiate\u00a0\u548c\u00a0NTLM\u00a0\u8eab\u4efd\u9a8c\u8bc1\u65b9\u6848)\uff0cSmtpClient\u00a0(GSSAPI\u00a0\u548c\u00a0NTLM\u00a0\u8eab\u4efd\u9a8c\u8bc1\u65b9\u6848)\uff0cNegotiateStream\u3001<a href=\"https:\/\/learn.microsoft.com\/aspnet\/core\/security\/authentication\/windowsauth?view=aspnetcore-7.0\">ASP.NET Core<\/a>\u548cSQL Server \u5ba2\u6237\u7aef\u5e93\u3002 \u867d\u7136\u8fd9\u6db5\u76d6\u4e86\u6700\u7ec8\u7528\u6237\u7684\u5927\u591a\u6570\u573a\u666f\uff0c\u4f46\u5b83\u5bf9\u5e93\u4f5c\u8005\u6765\u8bf4\u662f\u6709\u9650\u7684\u3002\u5176\u4ed6\u5e93\uff0c\u5982<a href=\"https:\/\/www.npgsql.org\/\">Npgsql PostgreSQL client<\/a>\u3001\u00a0<a href=\"https:\/\/github.com\/jstedfast\/MailKit\">MailKit<\/a>\u3001\u00a0<a href=\"https:\/\/github.com\/xqrzd\/kudu-client-net\">Apache Kudu client<\/a>\u00a0\u9700\u8981\u8bc9\u8bf8\u5404\u79cd\u6280\u5de7\uff0c\u4e3a\u5e76\u975e\u57fa\u4e8e HTTP \u6216\u5176\u4ed6\u53ef\u7528\u7684\u9ad8\u7ea7\u6784\u5efa\u5757\u6784\u5efa\u7684\u4f4e\u7ea7\u534f\u8bae\u5b9e\u65bd\u76f8\u540c\u7684\u8eab\u4efd\u9a8c\u8bc1\u65b9\u6848\u3002<\/p>\n<p>.NET 7 \u5f15\u5165\u4e86\u65b0\u7684 API\uff0c\u63d0\u4f9b\u4f4e\u7ea7\u6784\u5efa\u5757\u6765\u6267\u884c\u4e0a\u8ff0\u534f\u8bae\u7684\u8eab\u4efd\u9a8c\u8bc1\u4ea4\u6362\uff0c\u8bf7\u53c2\u9605<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/69920\">dotnet\/runtime#69920<\/a>\u3002\u4e0e.NET \u4e2d\u7684\u6240\u6709\u5176\u4ed6API \u4e00\u6837\uff0c \u5b83\u5728\u6784\u5efa\u65f6\u8003\u8651\u4e86\u8de8\u5e73\u53f0\u4e92\u64cd\u4f5c\u6027\u3002\u5728 Linux\u3001 macOS\u3001iOS\u548c\u5176\u4ed6\u7c7b\u4f3c\u5e73\u53f0\u4e0a\uff0c\u5b83\u4f7f\u7528 GSSAPI \u7cfb\u7edf\u5e93\u3002\u5728 Windows\u4e0a\uff0c\u5b83\u4f9d\u8d56\u4e8e<a href=\"https:\/\/learn.microsoft.com\/windows\/win32\/rpc\/sspi-architectural-overview\">SSPI<\/a>\u00a0\u5e93\u3002\u5bf9\u4e8e\u7cfb\u7edf\u5b9e\u73b0\u4e0d\u53ef\u7528\u7684\u5e73\u53f0\uff0c\u4f8b\u5982Android \u548c tvOS\uff0c\u5b58\u5728\u6709\u9650\u7684\u4ec5\u5ba2\u6237\u7aef\u5b9e\u73b0\u3002<\/p>\n<h3>\u5982\u4f55\u4f7f\u7528 API<\/h3>\n<p>\u4e3a\u4e86\u7406\u89e3\u8eab\u4efd\u9a8c\u8bc1 API \u7684\u5de5\u4f5c\u539f\u7406\uff0c\u8ba9\u6211\u4eec\u4ece\u4e00\u4e2a\u793a\u4f8b\u5f00\u59cb\uff0c\u4e86\u89e3\u8eab\u4efd\u9a8c\u8bc1\u4f1a\u8bdd\u5728 SMTP \u7b49\u9ad8\u7ea7\u534f\u8bae\u4e2d\u7684\u5916\u89c2\u3002\u8be5\u793a\u4f8b\u53d6\u81ea\u00a0<a href=\"https:\/\/learn.microsoft.com\/openspecs\/windows_protocols\/ms-ssean\/0fa15a99-af88-428a-a51d-742b8450d877\">Microsoft protocol documentation<\/a>\uff0c\u8be5\u6587\u6863\u5bf9\u5176\u8fdb\u884c\u4e86\u66f4\u8be6\u7ec6\u7684\u89e3\u91ca\u3002<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">S: 220 server.contoso.com Authenticated Receive Connector\r\nC: EHLO client.contoso.com\r\nS: 250-server-contoso.com Hello [203.0.113.1]\r\nS: 250-AUTH GSSAPI NTLM\r\nS: 250 OK\r\nC: AUTH GSSAPI &lt;token1&gt;\r\nS: 334 &lt;token2&gt;\r\nC: &lt;token3&gt;\r\nS: 235 2.7.0 Authentication successful<\/code><\/pre>\n<p>\u8eab\u4efd\u9a8c\u8bc1\u4ece\u5ba2\u6237\u7aef\u751f\u6210\u8d28\u8be2\u4ee4\u724c\u5f00\u59cb\u3002\u7136\u540e\u670d\u52a1\u5668\u4ea7\u751f\u54cd\u5e94\u3002\u5ba2\u6237\u7aef\u5904\u7406\u54cd\u5e94\uff0c\u5e76\u5411\u670d\u52a1\u5668\u53d1\u9001\u65b0\u7684\u8d28\u8be2\u3002\u8fd9\u79cd\u8d28\u8be2\/\u54cd\u5e94\u4ea4\u6362\u53ef\u4ee5\u53d1\u751f\u591a\u6b21\u3002\u5f53\u4efb\u4f55\u4e00\u65b9\u62d2\u7edd\u8ba4\u8bc1\u6216\u53cc\u65b9\u90fd\u63a5\u53d7\u8ba4\u8bc1\u65f6\uff0c\u5b83\u7ed3\u675f\u3002\u4ee4\u724c\u7684\u683c\u5f0f\u7531 Windows \u8eab\u4efd\u9a8c\u8bc1\u534f\u8bae\u5b9a\u4e49\uff0c\u800c\u5c01\u88c5\u662f\u9ad8\u7ea7\u534f\u8bae\u89c4\u8303\u7684\u4e00\u90e8\u5206\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0cSMTP \u534f\u8bae\u9884\u5148\u6dfb\u52a0334\u00a0\u4ee3\u7801\u4ee5\u544a\u77e5\u5ba2\u6237\u7aef\u670d\u52a1\u5668\u4ea7\u751f\u4e86\u8eab\u4efd\u9a8c\u8bc1\u54cd\u5e94\uff0c\u8be5235\u00a0\u4ee3\u7801\u8868\u793a\u200b\u200b\u8eab\u4efd\u9a8c\u8bc1\u6210\u529f\u3002<\/p>\n<p>\u5927\u90e8\u5206\u65b0 API \u90fd\u4ee5\u65b0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.negotiateauthentication?view=net-7.0\">NegotiateAuthentication<\/a>\u00a0\u7c7b\u4e3a\u4e2d\u5fc3\u3002\u5b83\u7528\u4e8e\u5b9e\u4f8b\u5316\u5ba2\u6237\u7aef\u6216\u670d\u52a1\u5668\u7aef\u8eab\u4efd\u9a8c\u8bc1\u7684\u4e0a\u4e0b\u6587\u3002\u6709\u591a\u79cd\u9009\u9879\u53ef\u4ee5\u6307\u5b9a\u5efa\u7acb\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u7684\u4f1a\u8bdd\u7684\u8981\u6c42\uff0c\u4f8b\u5982\u8981\u6c42\u52a0\u5bc6\u6216\u786e\u5b9a\u8981\u4f7f\u7528\u7684\u7279\u5b9a\u534f\u8bae (Negotiate, Kerberos \u6216 NTLM) \u6307\u5b9a\u53c2\u6570\u540e\uff0c\u8eab\u4efd\u9a8c\u8bc1\u5c06\u901a\u8fc7\u5728\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u4ea4\u6362\u8eab\u4efd\u9a8c\u8bc1\u8d28\u8be2\/\u54cd\u5e94\u6765\u8fdb\u884c\u3002<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.negotiateauthentication.getoutgoingblob?view=net-7.0\">GetOutgoingBlob<\/a>\u00a0\u65b9\u6cd5\u7528\u4e8e\u6b64\u76ee\u7684\u3002\u5b83\u53ef\u4ee5\u5904\u7406\u5b57\u8282\u8de8\u5ea6\u6216base64 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u5c06\u540c\u65f6\u6267\u884c\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\uff0c\u5bf9\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u7684\u5f53\u524d\u7528\u6237\u8fdb\u884c\u90e8\u5206\u8eab\u4efd\u9a8c\u8bc1\uff1a<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">using System.Net;\r\nusing System.Net.Security;\r\n\r\nvar serverAuthentication = new NegotiateAuthentication(new NegotiateAuthenticationServerOptions { });\r\nvar clientAuthentication = new NegotiateAuthentication(\r\n    new NegotiateAuthenticationClientOptions\r\n    {\r\n        Package = \"Negotiate\",\r\n        Credential = CredentialCache.DefaultNetworkCredentials,\r\n        TargetName = \"HTTP\/localhost\",\r\n        RequiredProtectionLevel = ProtectionLevel.Sign\r\n    });\r\n\r\nstring? serverBlob = null;\r\nwhile (!clientAuthentication.IsAuthenticated)\r\n{\r\n    \/\/ Client produces the authentication challenge, or response to server's challenge\r\n    string? clientBlob = clientAuthentication.GetOutgoingBlob(serverBlob, out var clientStatusCode);\r\n    if (clientStatusCode == NegotiateAuthenticationStatusCode.ContinueNeeded)\r\n    {\r\n        \/\/ Send the client blob to the server; this would normally happen over a network\r\n        Console.WriteLine($\"C: {clientBlob}\");\r\n        serverBlob = serverAuthentication.GetOutgoingBlob(clientBlob, out var serverStatusCode);\r\n        if (serverStatusCode != NegotiateAuthenticationStatusCode.Completed &amp;&amp;\r\n            serverStatusCode != NegotiateAuthenticationStatusCode.ContinueNeeded)\r\n        {\r\n            Console.WriteLine($\"Server authentication failed with status code {serverStatusCode}\");\r\n            break;\r\n        }\r\n        Console.WriteLine($\"S: {serverBlob}\");\r\n    }\r\n    else\r\n    {\r\n        Console.WriteLine(\r\n            clientStatusCode == NegotiateAuthenticationStatusCode.Completed ?\r\n            \"Successfully authenticated\" :\r\n            $\"Authentication failed with status code {clientStatusCode}\");\r\n        break;\r\n    }\r\n}<\/code><\/pre>\n<p>\u4e00\u65e6\u5efa\u7acb\u4e86\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u7684\u4f1a\u8bdd\uff0cNegotiateAuthentication\u00a0\u5b9e\u4f8b\u5c31\u53ef\u4ee5\u7528\u4e8e\u5bf9\u4f20\u51fa\u6d88\u606f\u8fdb\u884c\u7b7e\u540d\/\u52a0\u5bc6\u5e76\u9a8c\u8bc1\/\u89e3\u5bc6\u4f20\u5165\u6d88\u606f\u3002\u8fd9\u662f\u901a\u8fc7\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.negotiateauthentication.wrap?view=net-7.0\">Wrap<\/a>\u00a0\u548c\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.negotiateauthentication.unwrap?view=net-7.0\">Unwrap<\/a>\u00a0\u65b9\u6cd5\u5b8c\u6210\u7684\u3002<\/p>\n<p>\u5b8c\u6210\u6b64\u66f4\u6539\u4ee5\u53ca\u6587\u7ae0\u7684\u8fd9\u4e00\u90e8\u5206\u662f\u7531\u793e\u533a\u8d21\u732e\u8005<a href=\"https:\/\/github.com\/filipnavara\">@filipnavara<\/a>\u64b0\u5199\u7684\u3002\u8c22\u8c22\uff01<\/p>\n<h3 lang=\"zh-CN\">\u8bc1\u4e66\u9a8c\u8bc1\u9009\u9879<\/h3>\n<p>\u5f53\u5ba2\u6237\u7aef\u6536\u5230\u670d\u52a1\u5668\u7684\u8bc1\u4e66\u65f6\uff0c\u53cd\u4e4b\u4ea6\u7136\uff0c\u5982\u679c\u8bf7\u6c42\u5ba2\u6237\u7aef\u8bc1\u4e66\uff0c\u8bc1\u4e66\u5c06\u901a\u8fc7<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.security.cryptography.x509certificates.x509chain?view=net-7.0\">X509Chain<\/a>\u3002\u9a8c\u8bc1\u59cb\u7ec8\u8fdb\u884c\uff0c\u5373\u4f7f<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.remotecertificatevalidationcallback?view=net-7.0\">RemoteCertificateValidationCallback<\/a>\u00a0\u63d0\u4f9b\u4e86\u9a8c\u8bc1\uff0c\u5e76\u4e14\u5728\u9a8c\u8bc1\u671f\u95f4\u53ef\u80fd\u4f1a\u4e0b\u8f7d\u5176\u4ed6\u8bc1\u4e66\u3002\u7531\u4e8e\u65e0\u6cd5\u63a7\u5236\u6b64\u884c\u4e3a\uff0c\u56e0\u6b64\u63d0\u51fa\u4e86\u51e0\u4e2a\u95ee\u9898\u3002\u5176\u4e2d\u5305\u62ec\u5b8c\u5168\u963b\u6b62\u8bc1\u4e66\u4e0b\u8f7d\u3001\u8bbe\u7f6e\u8d85\u65f6\u6216\u63d0\u4f9b\u81ea\u5b9a\u4e49\u5b58\u50a8\u4ee5\u4ece\u4e2d\u83b7\u53d6\u8bc1\u4e66\u7684\u8981\u6c42\u3002\u4e3a\u4e86\u7f13\u89e3\u8fd9\u6574\u7ec4\u95ee\u9898\uff0c\u6211\u4eec\u51b3\u5b9a\u5728<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.sslclientauthenticationoptions?view=net-7.0\">SslClientAuthenticationOptions<\/a>\u00a0 \u548c<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.sslserverauthenticationoptions?view=net-7.0\">SslServerAuthenticationOptions<\/a>\u4e0a\u5f15\u5165\u4e00\u4e2a\u65b0\u5c5e\u6027CertificateChainPolicy\u3002\u6b64\u5c5e\u6027\u7684\u76ee\u6807\u662f\u5728<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.sslstream.authenticateasclientasync?view=net-7.0\">AuthenticateAsClientAsync<\/a>\u00a0\/\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.sslstream.authenticateasserverasync?view=net-7.0\">AuthenticateAsServerAsync<\/a>\u64cd\u4f5c\u671f\u95f4\u751f\u6210\u94fe\u65f6\u8986\u76d6<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.sslstream?view=net-7.0\">SslStream<\/a>\u00a0\u7684\u9ed8\u8ba4\u884c\u4e3a\u3002\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.security.cryptography.x509certificates.x509chainpolicy?view=net-7.0\">X509ChainPolicy<\/a>\u00a0\u5728\u540e\u53f0\u81ea\u52a8\u6784\u5efa\u3002\u4f46\u662f\uff0c\u5982\u679c\u6307\u5b9a\u4e86\u8fd9\u4e2a\u65b0\u5c5e\u6027\uff0c\u5b83\u5c06\u4f18\u5148\u5e76\u88ab\u4f7f\u7528\uff0c\u4ece\u800c\u4f7f\u7528\u6237\u80fd\u591f\u5b8c\u5168\u63a7\u5236\u8bc1\u4e66\u9a8c\u8bc1\u8fc7\u7a0b\u3002<\/p>\n<p>\u94fe\u7b56\u7565\u7684\u7528\u6cd5\u53ef\u80fd\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">\/\/ Client side:\r\nvar policy = new X509ChainPolicy();\r\npolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;\r\npolicy.ExtraStore.Add(s_ourPrivateRoot);\r\npolicy.UrlRetrievalTimeout = TimeSpan.FromSeconds(3);\r\n\r\nvar options  = new SslClientAuthenticationOptions();\r\noptions.TargetHost = \"myServer\";\r\noptions.CertificateChainPolicy = policy;\r\n\r\nvar sslStream = new SslStream(transportStream);\r\nsslStream.AuthenticateAsClientAsync(options, cancellationToken);\r\n\r\n\/\/ Server side:\r\nvar policy = new X509ChainPolicy();\r\npolicy.DisableCertificateDownloads = true;\r\n\r\nvar options  = new SslServerAuthenticationOptions();\r\noptions.CertificateChainPolicy = policy;\r\n\r\nvar sslStream = new SslStream(transportStream);\r\nsslStream.AuthenticateAsServerAsync(options, cancellationToken);<\/code><\/pre>\n<p>\u66f4\u591a\u4fe1\u606f\u53ef\u4ee5\u5728 API \u63d0\u6848 (<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/71191\">dotnet\/runtime#71191<\/a>) \u4e2d\u627e\u5230\u3002<\/p>\n<h3>\u8868\u73b0<\/h3>\n<p>Stephen\u7684\u6587\u7ae0<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/performance_improvements_in_net_7\/#networking\">Performance Improvements in .NET 7 \u2013 Networking<\/a>\u6db5\u76d6\u4e86 .NET 7 \u4e2d\u7684\u5927\u90e8\u5206\u7f51\u7edc\u6027\u80fd\u6539\u8fdb\uff0c\u4f46\u4e00\u4e9b\u5b89\u5168\u6027\u6539\u8fdb\u503c\u5f97\u518d\u6b21\u63d0\u53ca\u3002<\/p>\n<h3>TLS \u7b80\u4ecb<\/h3>\n<p>\u5efa\u7acb\u65b0\u7684TLS \u8fde\u63a5\u662f\u76f8\u5f53\u6602\u8d35\u7684\u64cd\u4f5c\uff0c\u56e0\u4e3a\u5b83\u9700\u8981\u591a\u4e2a\u6b65\u9aa4\u548c\u591a\u6b21\u5f80\u8fd4\u3002\u5728\u7ecf\u5e38\u91cd\u65b0\u521b\u5efa\u4e0e\u540c\u4e00\u670d\u52a1\u5668\u7684\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\uff0c\u63e1\u624b\u6240\u6d88\u8017\u7684\u65f6\u95f4\u5c06\u52a0\u8d77\u6765\u3002TLS \u63d0\u4f9b\u7684\u88ab\u79f0\u4e3a\u4f1a\u8bdd\u6062\u590d\u7684\u529f\u80fd\u53ef\u4ee5\u7f13\u89e3\u8fd9\u79cd\u60c5\u51b5\uff0c\u8bf7\u53c2\u9605<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc5246.html#section-7.3\">RFC 5246 Section 7.3<\/a>\u00a0\u548c\u00a0<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc8446#section-2.2\">RFC 8446 Section 2.2<\/a>\u3002 \u7b80\u800c\u8a00\u4e4b\uff0c\u5728\u63e1\u624b\u671f\u95f4\uff0c\u5ba2\u6237\u7aef\u53ef\u4ee5\u53d1\u9001\u5148\u524d\u5efa\u7acb\u7684TLS \u4f1a\u8bdd\u7684\u6807\u8bc6\uff0c\u5982\u679c\u670d\u52a1\u5668\u540c\u610f\uff0c\u5219\u6839\u636e\u5148\u524d\u8fde\u63a5\u7684\u7f13\u5b58\u6570\u636e\u91cd\u65b0\u5efa\u7acb\u5b89\u5168\u4e0a\u4e0b\u6587\u3002\u5c3d\u7ba1\u4e0d\u540c TLS \u7248\u672c\u7684\u673a\u5236\u4e0d\u540c\uff0c\u4f46\u6700\u7ec8\u76ee\u6807\u662f\u76f8\u540c\u7684\uff0c\u5373\u5728\u91cd\u65b0\u5efa\u7acb\u4e0e\u5148\u524d\u8fde\u63a5\u7684\u670d\u52a1\u5668\u7684\u8fde\u63a5\u65f6\u8282\u7701\u5f80\u8fd4\u65f6\u95f4\u548c\u4e00\u4e9bCPU \u65f6\u95f4\u3002\u6b64\u529f\u80fd\u7531 Windows\u4e0a\u7684SChannel \u81ea\u52a8\u63d0\u4f9b\uff0c\u4f46\u5728Linux\u4e0a\u4f7f\u7528OpenSSL \u9700\u8981\u8fdb\u884c\u51e0\u5904\u66f4\u6539\u624d\u80fd\u542f\u7528\u6b64\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u670d\u52a1\u5668\u7aef\uff08\u65e0\u72b6\u6001\uff09 \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/57079\">dotnet\/runtime#57079<\/a>\u00a0\u548c\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/63030\">dotnet\/runtime#63030<\/a>.<\/li>\n<li>\u5ba2\u6237\u7aef \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/64369\">dotnet\/runtime#64369<\/a>.<\/li>\n<li>\u7f13\u5b58\u5927\u5c0f\u63a7\u5236 \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/69065\">dotnet\/runtime#69065<\/a>.<\/li>\n<\/ul>\n<p>\u5982\u679c\u4e0d\u9700\u8981\u7f13\u5b58TLS \u4e0a\u4e0b\u6587\uff0c\u53ef\u4ee5\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u201cDOTNET_SYSTEM_NET_SECURITY_DISABLETLSRESUME\u201d \u6216\u901a\u8fc7\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.appcontext.setswitch?view=net-7.0\">AppContext.SetSwitch<\/a>\u00a0\u201cSystem.Net.Security.TlsCacheSize\u201d \u5728\u8fdb\u7a0b\u8303\u56f4\u5185\u5173\u95ed\u5b83\u3002<\/p>\n<h3>OCSP Stapling<\/h3>\n<p>Online Certificate Status Protocol (OCSP) Stapling \u662f\u670d\u52a1\u5668\u63d0\u4f9b\u5df2\u7b7e\u540d\u548c\u65f6\u95f4\u6233\u8bc1\u660e\uff08OCSP \u54cd\u5e94\uff09\u7684\u673a\u5236\uff0c\u8bc1\u660e\u53d1\u9001\u7684\u8bc1\u4e66\u5c1a\u672a\u88ab\u540a\u9500\uff0c\u53c2\u89c1<u>RFC 6961<\/u>\u3002 \u56e0\u6b64\uff0c\u5ba2\u6237\u7aef\u65e0\u9700\u8054\u7cfb OCSP \u670d\u52a1\u5668\u672c\u8eab\uff0c\u4ece\u800c\u51cf\u5c11\u4e86\u5efa\u7acb\u8fde\u63a5\u6240\u9700\u7684\u8bf7\u6c42\u6570\u91cf\u4ee5\u53ca\u65bd\u52a0\u5728 OCSP \u670d\u52a1\u5668\u4e0a\u7684\u8d1f\u8f7d\u3002\u7531\u4e8e OCSP \u54cd\u5e94\u9700\u8981\u7531\u8bc1\u4e66\u9881\u53d1\u673a\u6784 \uff08CA\uff09 \u7b7e\u540d\uff0c\u56e0\u6b64\u63d0\u4f9b\u8bc1\u4e66\u7684\u670d\u52a1\u5668\u65e0\u6cd5\u4f2a\u9020\u5b83\u3002 \u5728\u6b64\u7248\u672c\u4e4b\u524d\uff0c\u6211\u4eec\u6ca1\u6709\u5229\u7528\u6b64 TLS \u529f\u80fd\uff0c\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\u8bf7\u53c2\u9605\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/33377\">dotnet\/runtime#33377<\/a>.<\/p>\n<h3 lang=\"zh-CN\">\u8de8\u5e73\u53f0\u7684\u4e00\u81f4\u6027<\/h3>\n<p>\u6211\u4eec\u77e5\u9053\uff0c.NET \u63d0\u4f9b\u7684\u67d0\u4e9b\u529f\u80fd\u4ec5\u5728\u67d0\u4e9b\u5e73\u53f0\u4e0a\u53ef\u7528\u3002\u4f46\u662f\u6bcf\u4e2a\u7248\u672c\u6211\u4eec\u90fd\u8bd5\u56fe\u8fdb\u4e00\u6b65\u7f29\u5c0f\u5dee\u8ddd\u3002\u5728 .NET 7 \u4e2d\uff0c\u6211\u4eec\u5bf9\u7f51\u7edc\u5b89\u5168\u7a7a\u95f4\u8fdb\u884c\u4e86\u4e00\u4e9b\u66f4\u6539\uff0c\u4ee5\u6539\u5584\u5dee\u5f02\uff1a<\/p>\n<ul>\n<li>\u5728\u9002\u7528\u4e8e TLS 1.3 \u7684 Linux \u4e0a\u652f\u6301\u63e1\u624b\u540e\u8ba4\u8bc1 \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/64268\">dotnet\/runtime#64268<\/a><\/li>\n<li>\u8fdc\u7a0b\u8bc1\u4e66\u73b0\u5df2\u5728 Windows \u4e0a\u8bbe\u7f6e \u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.security.sslclientauthenticationoptions.localcertificateselectioncallback?view=net-7.0\">SslClientAuthenticationOptions.LocalCertificateSelectionCallback<\/a>\u00a0\u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/65134\">dotnet\/runtime#65134<\/a><\/li>\n<li>\u652f\u6301\u5728 OSX \u548c Linux \u4e0a\u7684 TLS \u63e1\u624b\u4e2d\u53d1\u9001\u53d7\u4fe1\u4efb CA \u7684\u540d\u79f0 \u2013\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/pull\/65195\">dotnet\/runtime#65195<\/a><\/li>\n<\/ul>\n<h3>WebSockets<\/h3>\n<h3>WebSocket \u63e1\u624b\u54cd\u5e94\u8be6\u7ec6\u4fe1\u606f<\/h3>\n<p>\u5728 .NET 7 \u4e4b\u524d\uff0cWebSocket \u7684\u5f00\u573a\u63e1\u624b\uff08\u5bf9\u5347\u7ea7\u8bf7\u6c42\u7684 HTTP \u54cd\u5e94\uff09\u7684\u670d\u52a1\u5668\u54cd\u5e94\u90e8\u5206\u9690\u85cf\u5728 ClientWebSocket \u5b9e\u73b0\u4e2d\uff0c \u5e76\u4e14\u6240\u6709\u63e1\u624b\u9519\u8bef\u90fd\u5c06\u663e\u793a\u4e3a WebSocketException\uff0c\u5728\u5f02\u5e38\u4fe1\u606f\u65c1\u8fb9\u6ca1\u6709\u592a\u591a\u8be6\u7ec6\u4fe1\u606f\u3002 \u4f46\u662f\uff0c\u6709\u5173 HTTP \u54cd\u5e94\u6807\u5934\u548c\u72b6\u6001\u4ee3\u7801\u7684\u4fe1\u606f\u5728\u5931\u8d25\u548c\u6210\u529f\u65b9\u6848\u4e2d\u90fd\u53ef\u80fd\u5f88\u91cd\u8981\u3002 \u5982\u679c\u53d1\u751f\u6545\u969c\uff0cHTTP \u72b6\u6001\u4ee3\u7801\u53ef\u4ee5\u5e2e\u52a9\u533a\u5206\u53ef\u91cd\u8bd5\u548c\u4e0d\u53ef\u91cd\u8bd5\u7684\u9519\u8bef\uff08\u4f8b\u5982\uff0c\u670d\u52a1\u5668\u6839\u672c\u4e0d\u652f\u6301 WebSockets\uff0c\u6216\u8005\u53ea\u662f\u6682\u65f6\u6027\u7f51\u7edc\u9519\u8bef\uff09\u3002\u6807\u5934\u8fd8\u53ef\u80fd\u5305\u542b\u6709\u5173\u5982\u4f55\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\u7684\u5176\u4ed6\u4fe1\u606f\u3002\u5373\u4f7f\u5728 WebSocket \u63e1\u624b\u6210\u529f\u7684\u60c5\u51b5\u4e0b\uff0c\u6807\u5934\u4e5f\u5f88\u6709\u7528\uff0c\u4f8b\u5982\uff0c\u5b83\u4eec\u53ef\u4ee5\u5305\u542b\u4e0e\u4f1a\u8bdd\u7ed1\u5b9a\u7684\u4ee4\u724c\u3001\u4e0e\u5b50\u534f\u8bae\u7248\u672c\u76f8\u5173\u7684\u4fe1\u606f\uff0c\u6216\u8005\u670d\u52a1\u5668\u53ef\u80fd\u5f88\u5feb\u5173\u95ed\u7684\u4fe1\u606f\u3002<\/p>\n<p>.NET 7 \u5c06\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.collecthttpresponsedetails?view=net-7.0\">CollectHttpResponseDetails<\/a>\u00a0\u8bbe\u7f6e\u6dfb\u52a0\u5230 \u00a0ClientWebSocketOptions\u4e2d\uff0c\u8be5\u8bbe\u7f6e\u5141\u8bb8\u5728 <a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocket.connectasync?view=net-7.0\">ConnectAsync<\/a> \u8c03\u7528\u671f\u95f4\u6536\u96c6 ClientWebSocket \u5b9e\u4f8b\u4e2d\u7684\u5347\u7ea7\u54cd\u5e94\u8be6\u7ec6\u4fe1\u606f\u3002\u4f60\u7a0d\u540e\u53ef\u4ee5\u4f7f\u7528 ClientWebSocket \u5b9e\u4f8b\u7684 <a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocket.httpstatuscode?view=net-7.0\">HttpStatusCode<\/a> \u548c <a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocket.httpresponseheaders?view=net-7.0\">HttpResponseHeaders<\/a> \u5c5e\u6027\u8bbf\u95ee\u6570\u636e\uff0c\u5373\u4f7f\u5728 ConnectAsync \u5f15\u53d1\u5f02\u5e38\u7684\u60c5\u51b5\u4e0b\u4e5f\u662f\u5982\u6b64\u3002\u8bf7\u6ce8\u610f\uff0c\u5728\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u4fe1\u606f\u53ef\u80fd\u4e0d\u53ef\u7528\uff0c\u5373\u5982\u679c\u670d\u52a1\u5668\u4ece\u672a\u54cd\u5e94\u8bf7\u6c42\u3002<\/p>\n<p>\u53e6\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u8fde\u63a5\u6210\u529f\uff0c\u5e76\u4e14\u5728\u4f7f\u7528 HttpResponseHeaders \u6570\u636e\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06 ClientWebSocket.HttpResponseHeaders \u5c5e\u6027\u8bbe\u7f6e\u4e3a null \u6765\u51cf\u5c11 ClientWebSocket \u7684\u5185\u5b58\u5360\u7528\u91cf\u3002<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">var ws = new ClientWebSocket();\r\nws.Options.CollectHttpResponseDetails = true;\r\ntry\r\n{\r\n    await ws.ConnectAsync(uri, cancellationToken);\r\n    \/\/ success scenario\r\n    ProcessSuccess(ws.HttpResponseHeaders);\r\n    ws.HttpResponseHeaders = null; \/\/ clean up (if needed)\r\n}\r\ncatch (WebSocketException)\r\n{\r\n    \/\/ failure scenario\r\n    if (ws.HttpStatusCode != 0)\r\n    {\r\n        ProcessFailure(ws.HttpStatusCode, ws.HttpResponseHeaders);\r\n    }\r\n}<\/code><\/pre>\n<h3>\u63d0\u4f9b\u5916\u90e8  HTTP Client<\/h3>\n<p>\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cClientWebSocket \u4f7f\u7528\u7f13\u5b58\u7684\u9759\u6001 HttpMessageInvoker \u5b9e\u4f8b\u6765\u6267\u884c HTTP \u5347\u7ea7\u8bf7\u6c42\u3002 \u4f46\u662f\uff0c\u6709\u4e00\u4e9b\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocket.options?view=net-7.0#system-net-websockets-clientwebsocket-options\">ClientWebSocketOptions<\/a>\u00a0\u4f1a\u963b\u6b62\u7f13\u5b58\u8c03\u7528\u7a0b\u5e8f\uff0c\u4f8b\u5982 Proxy\u3001ClientCertificates \u6216 Cookie\u3002\u5177\u6709\u8fd9\u4e9b\u53c2\u6570\u7684 HttpMessageInvoker \u5b9e\u4f8b\u4e0d\u5b89\u5168\uff0c\u6bcf\u6b21\u8c03\u7528\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocket.connectasync?view=net-7.0#system-net-websockets-clientwebsocket-connectasync(system-uri-system-threading-cancellationtoken)\">ConnectAsync<\/a>\u00a0\u65f6\u90fd\u9700\u8981\u521b\u5efa\u3002\u8fd9\u4f1a\u5bfc\u81f4\u8bb8\u591a\u4e0d\u5fc5\u8981\u7684\u5206\u914d\uff0c\u5e76\u4f7f HttpMessageInvoker \u8fde\u63a5\u6c60\u65e0\u6cd5\u91cd\u7528\u3002<\/p>\n<p>.NET 7 \u5141\u8bb8\u60a8\u4f7f\u7528 <a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocket.connectasync?view=net-7.0#system-net-websockets-clientwebsocket-connectasync(system-uri-system-net-http-httpmessageinvoker-system-threading-cancellationtoken)\">ConnectAsync(Uri,\u00a0HttpMessageInvoker,\u00a0CancellationToken)<\/a> \u91cd\u8f7d\u5c06\u73b0\u6709\u7684 \u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.http.httpmessageinvoker?view=net-7.0\">HttpMessageInvoker<\/a>\u00a0(\u4f8b\u5982\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.http.httpclient?view=net-7.0\">HttpClient<\/a>) \u5b9e\u4f8b\u4f20\u9012\u7ed9 ConnectAsync \u8c03\u7528\u3002 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5c06\u4f7f\u7528\u63d0\u4f9b\u7684\u5b9e\u4f8b\u6267\u884c HTTP \u5347\u7ea7\u8bf7\u6c42\u3002<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">var httpClient = new HttpClient();\r\nvar ws = new ClientWebSocket();\r\nawait ws.ConnectAsync(uri, httpClient, cancellationToken);<\/code><\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u4f20\u9012\u4e86\u81ea\u5b9a\u4e49 HTTP \u8c03\u7528\u7a0b\u5e8f\uff0c\u5219\u4e0d\u5f97\u8bbe\u7f6e\u4ee5\u4e0b\u4efb\u4f55 ClientWebSocketOptions\uff0c\u800c\u5e94\u5728 HTTP \u8c03\u7528\u7a0b\u5e8f\u4e0a\u8bbe\u7f6e\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.clientcertificates?view=net-7.0\">ClientCertificates<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.cookies?view=net-7.0\">Cookies<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.credentials?view=net-7.0\">Credentials<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.proxy?view=net-7.0\">Proxy<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.remotecertificatevalidationcallback?view=net-7.0\">RemoteCertificateValidationCallback<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.usedefaultcredentials?view=net-7.0\">UseDefaultCredentials<\/a><\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u662f\u5728 HttpMessageInvoker \u5b9e\u4f8b\u4e0a\u8bbe\u7f6e\u6240\u6709\u8fd9\u4e9b\u9009\u9879\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">var handler = new HttpClientHandler();\r\nhandler.CookieContainer = cookies;\r\nhandler.UseCookies = cookies != null;\r\nhandler.ServerCertificateCustomValidationCallback = remoteCertificateValidationCallback;\r\nhandler.Credentials = useDefaultCredentials ?\r\n    CredentialCache.DefaultCredentials :\r\n    credentials;\r\nif (proxy == null)\r\n{\r\n    handler.UseProxy = false;\r\n}\r\nelse\r\n{\r\n    handler.Proxy = proxy;\r\n}\r\nif (clientCertificates?.Count &gt; 0)\r\n{\r\n    handler.ClientCertificates.AddRange(clientCertificates);\r\n}\r\nvar invoker = new HttpMessageInvoker(handler);\r\n\r\nvar ws = new ClientWebSocket();\r\nawait ws.ConnectAsync(uri, invoker, cancellationToken);<\/code><\/pre>\n<h3>WebSockets over HTTP\/2<\/h3>\n<p>.NET 7 \u8fd8\u589e\u52a0\u4e86\u901a\u8fc7 HTTP\/2 \u4f7f\u7528 WebSocket \u534f\u8bae\u7684\u529f\u80fd\uff0c\u5982<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc8441\">RFC 8441<\/a>\u4e2d\u6240\u8ff0\u3002 \u8fd9\u6837\uff0cWebSocket\u8fde\u63a5\u662f\u901a\u8fc7HTTP \/ 2\u8fde\u63a5\u4e0a\u7684\u5355\u4e2a\u6d41\u5efa\u7acb\u7684\u3002\u8fd9\u5141\u8bb8\u540c\u65f6\u5728\u591a\u4e2a WebSocket \u8fde\u63a5\u548c HTTP \u8bf7\u6c42\u4e4b\u95f4\u5171\u4eab\u5355\u4e2a TCP \u8fde\u63a5\uff0c\u4ece\u800c\u66f4\u6709\u6548\u5730\u4f7f\u7528\u7f51\u7edc\u3002<\/p>\n<p>\u8981\u901a\u8fc7 HTTP\/2 \u542f\u7528 WebSockets\uff0c\u60a8\u53ef\u4ee5\u5c06 <a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.httpversion?view=net-7.0\">ClientWebSocketOptions.HttpVersion<\/a>\u00a0\u9009\u9879\u8bbe\u7f6e\u4e3aHttpVersion.Version20\u3002 \u60a8\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e \u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocketoptions.httpversionpolicy?view=net-7.0\">ClientWebSocketOptions.HttpVersionPolicy<\/a>\u00a0 \u5c5e\u6027\u6765\u542f\u7528\u6240\u4f7f\u7528\u7684 HTTP \u7248\u672c\u7684\u5347\u7ea7\/\u964d\u7ea7\u3002\u8fd9\u4e9b\u9009\u9879\u7684\u884c\u4e3a\u65b9\u5f0f\u4e0e HttpRequestMessage.Version \u548c HttpRequestMessage.VersionPolicy \u7684\u884c\u4e3a\u65b9\u5f0f\u76f8\u540c\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c06\u63a2\u6d4b HTTP\/2 WebSocket\uff0c\u5982\u679c\u65e0\u6cd5\u5efa\u7acb WebSocket \u8fde\u63a5\uff0c\u5b83\u5c06\u56de\u9000\u5230 HTTP\/1.1\uff1a<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">var ws = new ClientWebSocket();\r\nws.Options.HttpVersion = HttpVersion.Version20;\r\nws.Options.HttpVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;\r\nawait ws.ConnectAsync(uri, httpClient, cancellationToken);<\/code><\/pre>\n<p>HttpVersion.Version11 \u548c HttpVersionPolicy.RequestVersionOrHigher \u7684\u7ec4\u5408\u5c06\u5bfc\u81f4\u4e0e\u4e0a\u8ff0\u76f8\u540c\u7684\u884c\u4e3a\uff0c\u800c HttpVersionPolicy.RequestVersionExact \u5c06\u4e0d\u5141\u8bb8\u5347\u7ea7\/\u964d\u7ea7 HTTP \u7248\u672c\u3002<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8bbe\u7f6e\u4e86 HttpVersion = HttpVersion.Version11 \u548c HttpVersionPolicy = HttpVersionPolicy.RequestVersionOrLower\uff0c\u8fd9\u610f\u5473\u7740\u53ea\u4f1a\u4f7f\u7528 HTTP\/1.1\u3002<\/p>\n<p>\u901a\u8fc7\u5355\u4e2a HTTP\/2 \u8fde\u63a5\u591a\u8def\u590d\u7528 WebSocket \u8fde\u63a5\u548c HTTP \u8bf7\u6c42\u7684\u80fd\u529b\u662f\u6b64\u529f\u80fd\u7684\u5173\u952e\u90e8\u5206\u3002 \u4e3a\u4e86\u4f7f\u5b83\u6309\u9884\u671f\u5de5\u4f5c\uff0c\u60a8\u9700\u8981\u5728\u8c03\u7528 ConnectAsync \u65f6\u4ece\u4ee3\u7801\u4e2d\u4f20\u9012\u5e76\u91cd\u7528\u76f8\u540c\u7684 HttpMessageInvoker \u5b9e\u4f8b\uff08\u4f8b\u5982 HttpClient\uff09\uff0c\u5373\u4f7f\u7528\u00a0<a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.net.websockets.clientwebsocket.connectasync?view=net-7.0#system-net-websockets-clientwebsocket-connectasync(system-uri-system-net-http-httpmessageinvoker-system-threading-cancellationtoken)\">ConnectAsync(Uri,\u00a0HttpMessageInvoker,\u00a0CancellationToken)<\/a>\u00a0\u91cd\u8f7d\u3002 \u8fd9\u5c06\u91cd\u7528 HttpMessageInvoker \u5b9e\u4f8b\u4e2d\u7684\u8fde\u63a5\u6c60\u8fdb\u884c\u591a\u8def\u590d\u7528\u3002<\/p>\n<h3>\u7ed3\u8bed<\/h3>\n<p>\u6211\u4eec\u5c1d\u8bd5\u5728\u7f51\u7edc\u7a7a\u95f4\u4e2d\u6311\u9009\u6700\u6709\u8da3\u548c\u6700\u6709\u5f71\u54cd\u529b\u7684\u53d8\u5316\u3002 \u672c\u6587\u4e0d\u5305\u542b\u6211\u4eec\u6240\u505a\u7684\u6240\u6709\u66f4\u6539\uff0c\u4f46\u53ef\u4ee5\u5728\u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\">dotnet\/runtime<\/a>\u00a0\u5b58\u50a8\u5e93\u4e2d\u627e\u5230\u5b83\u4eec\u3002 \u50cf\u5f80\u5e38\u4e00\u6837\uff0c\u6027\u80fd\u6539\u8fdb\u5927\u591a\u88ab\u7701\u7565\uff0c\u56e0\u4e3a\u5b83\u4eec\u5728 Stephens \u7684\u6587\u7ae0\u00a0<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/performance_improvements_in_net_7\">Performance Improvements in .NET 7<\/a>\u4e2d\u5360\u6709\u4e00\u5e2d\u4e4b\u5730\u3002 \u6211\u4eec\u4e5f\u5e0c\u671b\u6536\u5230\u60a8\u7684\u6765\u4fe1\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u9047\u5230\u95ee\u9898\u6216\u6709\u4efb\u4f55\u53cd\u9988\uff0c\u53ef\u4ee5\u5728\u6211\u4eec\u7684 <a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\">GitHub<\/a> \u4e2d\u63d0\u4ea4\u3002 \u6700\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u6b64\u5904\u627e\u5230\u4ee5\u524d\u7248\u672c\u7684\u7c7b\u4f3c\u535a\u5ba2\u6587\u7ae0\uff1a\u00a0<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/dotnet-6-networking-improvements\/\">.NET 6 Networking Improvements<\/a>,\u00a0<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/net-5-new-networking-improvements\/\">.NET 5 Networking Improvements<\/a>.<\/p>\n<p>\u611f\u8c22\u60a8\u6210\u4e3a.NET\u4e2d\u7684\u4e00\u5458\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u65b0\u7684.NET 7\u73b0\u5df2\u53d1\u5e03\uff0c\u6211\u4eec\u60f3\u4ecb\u7ecd\u4e00\u4e0b\u5176\u5728\u7f51\u7edc\u9886\u57df\u6240\u505a\u7684\u4e00\u4e9b\u6709\u8da3\u7684\u66f4\u6539\u548c\u6dfb\u52a0\u3002\u8fd9\u7bc7\u535a\u6587\u8ba8\u8bba\u4e86 .NET 7 \u5728HTTP \u7a7a\u95f4\u3001\u65b0 QUIC API\u3001\u7f51\u7edc\u5b89\u5168\u548cWebSockets\u65b9\u9762\u7684\u53d8\u5316\u3002 HTTP \u6539\u8fdb\u4e86\u5bf9\u8fde\u63a5\u5c1d\u8bd5\u5931\u8d25\u7684\u5904\u7406 \u5728 .NET 6 \u4e4b\u524d\u7684\u7248\u672c\u4e2d\uff0c\u5982\u679c\u8fde\u63a5\u6c60\u4e2d\u6ca1\u6709\u7acb\u5373\u53ef\u7528\u7684\u8fde\u63a5\uff0c\uff08\u5904\u7406\u7a0b\u5e8f\u4e0a\u7684\u8bbe\u7f6e\u5141\u8bb8\u7684\u60c5\u51b5\u4e0b\uff0c\u4f8b\u5982HTTP \/1.1\u4e2d\u7684MaxConnectionsPerServer\uff0c\u6216 HTTP\/2\u4e2d\u7684EnableMultipleHttp2Connections\uff09\u65b0\u7684 HTTP \u8bf7\u6c42\u59cb\u7ec8\u4f1a\u53d1\u8d77\u65b0\u7684\u8fde\u63a5\u5c1d\u8bd5\u5e76\u7b49\u5f85\u54cd\u5e94\u3002\u8fd9\u6837\u505a\u7684\u7f3a\u70b9\u662f\uff0c\u5efa\u7acb\u8be5\u8fde\u63a5\u9700\u8981\u4e00\u6bb5\u65f6\u95f4\uff0c\u800c\u5728\u8fd9\u6bb5\u65f6\u95f4\u91cc\u5982\u679c\u53e6\u4e00\u4e2a\u8fde\u63a5\u5df2\u7ecf\u53ef\u7528\uff0c\u8be5\u8bf7\u6c42\u4ecd\u5c06\u7ee7\u7eed\u7b49\u5f85\u5b83\u751f\u6210\u7684\u8fde\u63a5\uff0c\u4ece\u800c\u5f71\u54cd\u5ef6\u8fdf\u3002\u5728 .NET 6.0\u4e2d\u6211\u4eec\u6539\u53d8\u4e86\u8fd9\u4e00\u8fdb\u7a0b\uff0c\u65e0\u8bba\u662f\u65b0\u5efa\u7acb\u7684\u8fde\u63a5\u8fd8\u662f\u4e0e\u6b64\u540c\u65f6\u51c6\u5907\u597d\u5904\u7406\u8bf7\u6c42\u7684\u53e6\u4e00\u4e2a\u8fde\u63a5\uff0c\u7b2c\u4e00\u4e2a\u53ef\u7528\u7684\u8fde\u63a5\u4f1a\u5904\u7406\u8bf7\u6c42\u3002\u8fd9\u6837\u4ecd\u4f1a\u4e00\u4e2a\u65b0\u8fde\u63a5\u88ab\u5efa\u7acb\uff08\u53d7\u9650\u5236\uff09\uff0c\u5982\u679c\u53d1\u8d77\u7684\u8bf7\u6c42\u672a\u4f7f\u7528\u8fd9\u4e00\u8fde\u63a5\uff0c\u5219\u5b83\u4f1a\u88ab\u5408\u5e76\u4ee5\u4f9b\u540e\u7eed\u8bf7\u6c42\u4f7f\u7528\u3002 \u4e0d\u5e78\u7684\u662f\uff0c.NET 6.0 \u4e2d\u7684\u8fd9\u4e00\u529f\u80fd\u5bf9\u67d0\u4e9b\u7528\u6237\u6765\u8bf4\u662f\u6709\u95ee\u9898\u7684\uff1a\u5931\u8d25\u7684\u8fde\u63a5\u5c1d\u8bd5\u4e5f\u4f1a\u4f7f\u4f4d\u4e8e\u8bf7\u6c42\u961f\u5217\u9876\u90e8\u7684\u8bf7\u6c42\u5931\u8d25\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u5bfc\u81f4\u610f\u5916\u7684\u8bf7\u6c42\u5931\u8d25\u3002\u6b64\u5916\uff0c\u5982\u679c\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\uff08\u4f8b\u5982\u7531\u4e8e\u670d\u52a1\u5668\u884c\u4e3a\u4e0d\u5f53\u6216\u7f51\u7edc\u95ee\u9898\uff09\u6c60\u4e2d\u6709\u4e00\u4e2a\u6c38\u8fdc\u672a\u88ab\u4f7f\u7528\u7684\u8fde\u63a5\uff0c\u4e0e\u4e4b\u5173\u8054\u7684\u65b0\u4f20\u5165\u7684\u8bf7\u6c42\u4e5f\u5c06\u5ef6\u8fdf\u5e76\u53ef\u80fd\u8d85\u65f6\u3002 \u5728 .NET 7.0 \u4e2d\uff0c\u6211\u4eec\u5b9e\u65bd\u4e86\u4ee5\u4e0b\u66f4\u6539\u6765\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff1a \u5931\u8d25\u7684\u8fde\u63a5\u5c1d\u8bd5\u53ea\u80fd\u4f7f\u5176\u76f8\u5173\u7684\u53d1\u8d77\u8bf7\u6c42\u5931\u8d25\uff0c\u800c\u4e0d\u4f1a\u5bfc\u81f4\u65e0\u5173\u7684\u8bf7\u6c42\u5931\u8d25\u3002\u5982\u679c\u5728\u8fde\u63a5\u5931\u8d25\u65f6\u539f\u59cb\u8bf7\u6c42\u5df2\u5f97\u5230\u5904\u7406\uff0c\u5219\u8fde\u63a5\u5931\u8d25\u5c06\u88ab\u5ffd\u7565 (\u00a0dotnet\/runtime#62935\u00a0)\u3002 \u5982\u679c\u4e00\u4e2a\u8bf7\u6c42\u53d1\u8d77\u4e86\u4e00\u4e2a\u65b0\u8fde\u63a5\uff0c\u4f46\u968f\u540e\u88ab\u6c60\u4e2d\u7684\u53e6\u4e00\u4e2a\u8fde\u63a5\u5904\u7406\uff0c\u5219\u65b0\u7684\u5f85\u4f7f\u7528\u7684\u8fde\u63a5\u5c1d\u8bd5\u5c06\u4e0d\u7ba1ConnectTimeout\uff0c\u5728\u77ed\u65f6\u95f4\u540e\u81ea\u52a8\u8d85\u65f6\u3002\u901a\u8fc7\u6b64\u66f4\u6539\uff0c\u5ef6\u8fdf\u7684\u8fde\u63a5\u5c06\u4e0d\u4f1a\u5ef6\u8fdf\u4e0d\u76f8\u5173\u7684\u8bf7\u6c42 (\u00a0dotnet\/runtime#71785\u00a0)\u3002\u8bf7\u6ce8\u610f\uff0c\u4e0d\u88ab\u4f7f\u7528\u7684\u8fde\u63a5\u5c1d\u8bd5\u81ea\u52a8\u8d85\u65f6\u5931\u8d25\u7684\u8fd9\u4e00\u8fdb\u7a0b\u53ea\u4f1a\u5728\u540e\u53f0\u81ea\u5df1\u8fd0\u884c\uff0c\u7528\u6237\u4e0d\u4f1a\u770b\u5230\u6b64\u8fdb\u7a0b\u3002\u89c2\u5bdf\u5b83\u4eec\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u542f\u7528telemetry\u3002 HttpHeaders \u8bfb\u53d6\u7ebf\u7a0b\u5b89\u5168 \u8fd9\u4e9bHttpHeaders\u96c6\u5408\u4ece\u6765\u90fd\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u8bbf\u95eeheader\u53ef\u80fd\u4f1a\u5f3a\u5236\u5ef6\u8fdf\u89e3\u6790\u5b83\u7684\u503c\uff0c\u4ece\u800c\u5bfc\u81f4\u5bf9\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u7684\u4fee\u6539\u3002 \u5728 .NET 6 \u4e4b\u524d\uff0c\u540c\u65f6\u8bfb\u53d6\u96c6\u5408\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u6070\u597d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002 \u4ece .NET 6 \u5f00\u59cb\uff0c\u7531\u4e8e\u5185\u90e8\u4e0d\u518d\u9700\u8981\u9501\u5b9a\uff0c\u9488\u5bf9header\u89e3\u6790\u6267\u884c\u7684\u9501\u5b9a\u8f83\u5c11\u3002\u8fd9\u4e00\u53d8\u5316\u5bfc\u81f4\u8bb8\u591a\u7528\u6237\u9519\u8bef\u5730\u540c\u65f6\u8bbf\u95eeheader\uff0c\u4f8b\u5982\uff0c\u5728 gRPC (\u00a0dotnet\/runtime#55898\u00a0)\u3001NewRelic (\u00a0newrelic\/newrelic-dotnet-agent#803\u00a0) \u751a\u81f3 HttpClient \u672c\u8eab (\u00a0dotnet\/runtime #65379\uff09\u3002\u8fdd\u53cd .NET 6 \u4e2d\u7684\u7ebf\u7a0b\u5b89\u5168\u53ef\u80fd\u4f1a\u5bfc\u81f4header\u503c\u91cd\u590d\/\u683c\u5f0f\u9519\u8bef\u6216\u5728\u679a\u4e3e\uff08enumeration\uff09\/header\u8bbf\u95ee\u671f\u95f4\u4ea7\u751f\u5404\u79cd\u5f02\u5e38\u3002 .NET 7 [&hellip;]<\/p>\n","protected":false},"author":99475,"featured_media":203,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2,11],"class_list":["post-197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet-ch","tag-net","tag-networking"],"acf":[],"blog_post_summary":"<p>\u6700\u65b0\u7684.NET 7\u73b0\u5df2\u53d1\u5e03\uff0c\u6211\u4eec\u60f3\u4ecb\u7ecd\u4e00\u4e0b\u5176\u5728\u7f51\u7edc\u9886\u57df\u6240\u505a\u7684\u4e00\u4e9b\u6709\u8da3\u7684\u66f4\u6539\u548c\u6dfb\u52a0\u3002\u8fd9\u7bc7\u535a\u6587\u8ba8\u8bba\u4e86 .NET 7 \u5728HTTP \u7a7a\u95f4\u3001\u65b0 QUIC API\u3001\u7f51\u7edc\u5b89\u5168\u548cWebSockets\u65b9\u9762\u7684\u53d8\u5316\u3002 HTTP \u6539\u8fdb\u4e86\u5bf9\u8fde\u63a5\u5c1d\u8bd5\u5931\u8d25\u7684\u5904\u7406 \u5728 .NET 6 \u4e4b\u524d\u7684\u7248\u672c\u4e2d\uff0c\u5982\u679c\u8fde\u63a5\u6c60\u4e2d\u6ca1\u6709\u7acb\u5373\u53ef\u7528\u7684\u8fde\u63a5\uff0c\uff08\u5904\u7406\u7a0b\u5e8f\u4e0a\u7684\u8bbe\u7f6e\u5141\u8bb8\u7684\u60c5\u51b5\u4e0b\uff0c\u4f8b\u5982HTTP \/1.1\u4e2d\u7684MaxConnectionsPerServer\uff0c\u6216 HTTP\/2\u4e2d\u7684EnableMultipleHttp2Connections\uff09\u65b0\u7684 HTTP \u8bf7\u6c42\u59cb\u7ec8\u4f1a\u53d1\u8d77\u65b0\u7684\u8fde\u63a5\u5c1d\u8bd5\u5e76\u7b49\u5f85\u54cd\u5e94\u3002\u8fd9\u6837\u505a\u7684\u7f3a\u70b9\u662f\uff0c\u5efa\u7acb\u8be5\u8fde\u63a5\u9700\u8981\u4e00\u6bb5\u65f6\u95f4\uff0c\u800c\u5728\u8fd9\u6bb5\u65f6\u95f4\u91cc\u5982\u679c\u53e6\u4e00\u4e2a\u8fde\u63a5\u5df2\u7ecf\u53ef\u7528\uff0c\u8be5\u8bf7\u6c42\u4ecd\u5c06\u7ee7\u7eed\u7b49\u5f85\u5b83\u751f\u6210\u7684\u8fde\u63a5\uff0c\u4ece\u800c\u5f71\u54cd\u5ef6\u8fdf\u3002\u5728 .NET 6.0\u4e2d\u6211\u4eec\u6539\u53d8\u4e86\u8fd9\u4e00\u8fdb\u7a0b\uff0c\u65e0\u8bba\u662f\u65b0\u5efa\u7acb\u7684\u8fde\u63a5\u8fd8\u662f\u4e0e\u6b64\u540c\u65f6\u51c6\u5907\u597d\u5904\u7406\u8bf7\u6c42\u7684\u53e6\u4e00\u4e2a\u8fde\u63a5\uff0c\u7b2c\u4e00\u4e2a\u53ef\u7528\u7684\u8fde\u63a5\u4f1a\u5904\u7406\u8bf7\u6c42\u3002\u8fd9\u6837\u4ecd\u4f1a\u4e00\u4e2a\u65b0\u8fde\u63a5\u88ab\u5efa\u7acb\uff08\u53d7\u9650\u5236\uff09\uff0c\u5982\u679c\u53d1\u8d77\u7684\u8bf7\u6c42\u672a\u4f7f\u7528\u8fd9\u4e00\u8fde\u63a5\uff0c\u5219\u5b83\u4f1a\u88ab\u5408\u5e76\u4ee5\u4f9b\u540e\u7eed\u8bf7\u6c42\u4f7f\u7528\u3002 \u4e0d\u5e78\u7684\u662f\uff0c.NET 6.0 \u4e2d\u7684\u8fd9\u4e00\u529f\u80fd\u5bf9\u67d0\u4e9b\u7528\u6237\u6765\u8bf4\u662f\u6709\u95ee\u9898\u7684\uff1a\u5931\u8d25\u7684\u8fde\u63a5\u5c1d\u8bd5\u4e5f\u4f1a\u4f7f\u4f4d\u4e8e\u8bf7\u6c42\u961f\u5217\u9876\u90e8\u7684\u8bf7\u6c42\u5931\u8d25\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u5bfc\u81f4\u610f\u5916\u7684\u8bf7\u6c42\u5931\u8d25\u3002\u6b64\u5916\uff0c\u5982\u679c\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\uff08\u4f8b\u5982\u7531\u4e8e\u670d\u52a1\u5668\u884c\u4e3a\u4e0d\u5f53\u6216\u7f51\u7edc\u95ee\u9898\uff09\u6c60\u4e2d\u6709\u4e00\u4e2a\u6c38\u8fdc\u672a\u88ab\u4f7f\u7528\u7684\u8fde\u63a5\uff0c\u4e0e\u4e4b\u5173\u8054\u7684\u65b0\u4f20\u5165\u7684\u8bf7\u6c42\u4e5f\u5c06\u5ef6\u8fdf\u5e76\u53ef\u80fd\u8d85\u65f6\u3002 \u5728 .NET 7.0 \u4e2d\uff0c\u6211\u4eec\u5b9e\u65bd\u4e86\u4ee5\u4e0b\u66f4\u6539\u6765\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff1a \u5931\u8d25\u7684\u8fde\u63a5\u5c1d\u8bd5\u53ea\u80fd\u4f7f\u5176\u76f8\u5173\u7684\u53d1\u8d77\u8bf7\u6c42\u5931\u8d25\uff0c\u800c\u4e0d\u4f1a\u5bfc\u81f4\u65e0\u5173\u7684\u8bf7\u6c42\u5931\u8d25\u3002\u5982\u679c\u5728\u8fde\u63a5\u5931\u8d25\u65f6\u539f\u59cb\u8bf7\u6c42\u5df2\u5f97\u5230\u5904\u7406\uff0c\u5219\u8fde\u63a5\u5931\u8d25\u5c06\u88ab\u5ffd\u7565 (\u00a0dotnet\/runtime#62935\u00a0)\u3002 \u5982\u679c\u4e00\u4e2a\u8bf7\u6c42\u53d1\u8d77\u4e86\u4e00\u4e2a\u65b0\u8fde\u63a5\uff0c\u4f46\u968f\u540e\u88ab\u6c60\u4e2d\u7684\u53e6\u4e00\u4e2a\u8fde\u63a5\u5904\u7406\uff0c\u5219\u65b0\u7684\u5f85\u4f7f\u7528\u7684\u8fde\u63a5\u5c1d\u8bd5\u5c06\u4e0d\u7ba1ConnectTimeout\uff0c\u5728\u77ed\u65f6\u95f4\u540e\u81ea\u52a8\u8d85\u65f6\u3002\u901a\u8fc7\u6b64\u66f4\u6539\uff0c\u5ef6\u8fdf\u7684\u8fde\u63a5\u5c06\u4e0d\u4f1a\u5ef6\u8fdf\u4e0d\u76f8\u5173\u7684\u8bf7\u6c42 (\u00a0dotnet\/runtime#71785\u00a0)\u3002\u8bf7\u6ce8\u610f\uff0c\u4e0d\u88ab\u4f7f\u7528\u7684\u8fde\u63a5\u5c1d\u8bd5\u81ea\u52a8\u8d85\u65f6\u5931\u8d25\u7684\u8fd9\u4e00\u8fdb\u7a0b\u53ea\u4f1a\u5728\u540e\u53f0\u81ea\u5df1\u8fd0\u884c\uff0c\u7528\u6237\u4e0d\u4f1a\u770b\u5230\u6b64\u8fdb\u7a0b\u3002\u89c2\u5bdf\u5b83\u4eec\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u542f\u7528telemetry\u3002 HttpHeaders \u8bfb\u53d6\u7ebf\u7a0b\u5b89\u5168 \u8fd9\u4e9bHttpHeaders\u96c6\u5408\u4ece\u6765\u90fd\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u8bbf\u95eeheader\u53ef\u80fd\u4f1a\u5f3a\u5236\u5ef6\u8fdf\u89e3\u6790\u5b83\u7684\u503c\uff0c\u4ece\u800c\u5bfc\u81f4\u5bf9\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u7684\u4fee\u6539\u3002 \u5728 .NET 6 \u4e4b\u524d\uff0c\u540c\u65f6\u8bfb\u53d6\u96c6\u5408\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u6070\u597d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002 \u4ece .NET 6 \u5f00\u59cb\uff0c\u7531\u4e8e\u5185\u90e8\u4e0d\u518d\u9700\u8981\u9501\u5b9a\uff0c\u9488\u5bf9header\u89e3\u6790\u6267\u884c\u7684\u9501\u5b9a\u8f83\u5c11\u3002\u8fd9\u4e00\u53d8\u5316\u5bfc\u81f4\u8bb8\u591a\u7528\u6237\u9519\u8bef\u5730\u540c\u65f6\u8bbf\u95eeheader\uff0c\u4f8b\u5982\uff0c\u5728 gRPC (\u00a0dotnet\/runtime#55898\u00a0)\u3001NewRelic (\u00a0newrelic\/newrelic-dotnet-agent#803\u00a0) \u751a\u81f3 HttpClient \u672c\u8eab (\u00a0dotnet\/runtime #65379\uff09\u3002\u8fdd\u53cd .NET 6 \u4e2d\u7684\u7ebf\u7a0b\u5b89\u5168\u53ef\u80fd\u4f1a\u5bfc\u81f4header\u503c\u91cd\u590d\/\u683c\u5f0f\u9519\u8bef\u6216\u5728\u679a\u4e3e\uff08enumeration\uff09\/header\u8bbf\u95ee\u671f\u95f4\u4ea7\u751f\u5404\u79cd\u5f02\u5e38\u3002 .NET 7 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/users\/99475"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/comments?post=197"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/197\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media\/203"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media?parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/categories?post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/tags?post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}