@@ -27,9 +27,6 @@ public partial class WebManager : GameFrameworkModule, IWebManager
2727 // 正在处理的普通请求列表
2828 private readonly List < WebJsonData > m_SendingNormalList = new List < WebJsonData > ( 16 ) ;
2929
30- // 用于存储请求和响应数据的内存流
31- private readonly MemoryStream m_MemoryStream ;
32-
3330 // JSON内容类型常量
3431 private const string JsonContentType = "application/json; charset=utf-8" ;
3532
@@ -47,7 +44,6 @@ public partial class WebManager : GameFrameworkModule, IWebManager
4744 public WebManager ( )
4845 {
4946 MaxConnectionPerServer = 8 ;
50- m_MemoryStream = new MemoryStream ( ) ;
5147 Timeout = 5f ;
5248 }
5349
@@ -126,7 +122,6 @@ protected override void Shutdown()
126122
127123 m_SendingNormalList . Clear ( ) ;
128124 ShutdownBinary ( ) ;
129- m_MemoryStream . Dispose ( ) ;
130125 }
131126
132127 /// <summary>
@@ -419,14 +414,15 @@ private async void MakeJsonBytesRequest(WebJsonData webJsonData)
419414 {
420415 using ( Stream responseStream = response . GetResponseStream ( ) )
421416 {
422- m_MemoryStream . SetLength ( responseStream . Length ) ;
423- m_MemoryStream . Position = 0 ;
424- await responseStream . CopyToAsync ( m_MemoryStream ) ;
425- var resultData = m_MemoryStream . ToArray ( ) ;
417+ using ( var ms = new MemoryStream ( ) )
418+ {
419+ await responseStream . CopyToAsync ( ms ) ;
420+ var resultData = ms . ToArray ( ) ;
426421#if ENABLE_GAMEFRAMEX_WEB_RECEIVE_LOG
427422 Log . Debug ( $ "Web Response: { webJsonData . URL } \n Header: { GameFrameX . Runtime . Utility . Json . ToJson ( webJsonData . Header ) } \n Form: { GameFrameX . Runtime . Utility . Json . ToJson ( webJsonData . Form ) } \n Content: { resultData } ") ;
428423#endif
429- webJsonData . UniTaskCompletionBytesSource . SetResult ( new WebBufferResult ( webJsonData . UserData , resultData ) ) ; // 将流的内容复制到内存流中并转换为byte数组
424+ webJsonData . UniTaskCompletionBytesSource . SetResult ( new WebBufferResult ( webJsonData . UserData , resultData ) ) ; // 将流的内容复制到内存流中并转换为byte数组
425+ }
430426 }
431427 }
432428 }
0 commit comments