I recently upgraded Unity Version to 2020.3.14f1
then my web request routine cannot get webrequest’s response body when request code is 400 (BadRequest)
It was working fine with Unity 2018,Unity 2019.
but not working with Unity 2020.3.0f1,2020.3.14f1,2021.1.15f1
It crashed when I read WebException’s response stream.
IAsyncResult asyncResult = httpWebRequest.BeginGetResponse( new AsyncCallback( (IAsyncResult iarres) => {
string resultText = "";
System.Net.HttpStatusCode code = 0;
try
{
using ( System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)httpWebRequest.EndGetResponse( iarres ) )
{
using ( System.IO.StreamReader streamReader = new System.IO.StreamReader( response.GetResponseStream() ) )
{
resultText = streamReader.ReadToEnd();
}
code = response.StatusCode;
response.Close();
}
}
catch ( WebException ex )
{
if ( ex.Status == WebExceptionStatus.ProtocolError )
{
using ( var stream = ex.Response.GetResponseStream() )
{
using ( System.IO.StreamReader streamReader = new StreamReader( stream ) )
{
resultText = streamReader.ReadToEnd(); // Crashed at this line.
}
code = ((HttpWebResponse)ex.Response).StatusCode;
ex.Response.Close();
}
return;
}
}
}
It’s almost same issue described at below links
https://github.com/mono/mono/issues/10645
Any help will be appreciated!
Thanks!