|
c# webapi 服务器无法在已发送 HTTP 标头之后设置状态。
System.Web.HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadGateway;
res.Add("code", 502);
res.Add("msg", "多个存货编码中间请使用中英文逗号分割");
byte[] resbyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(res));
System.Web.HttpContext.Current.Response.Headers.Add("ContentType","application/json");
System.Web.HttpContext.Current.Response.OutputStream.Write(resbyte, 0, resbyte.Length);
System.Web.HttpContext.Current.Response.FlushAsync();
修改为如下
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.BufferOutput = true;
System.Web.HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadGateway;
res.Add("code", 502);
res.Add("msg", "多个存货编码中间请使用中英文逗号分割");
byte[] resbyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(res));
System.Web.HttpContext.Current.Response.Headers.Add("ContentType","application/json");
System.Web.HttpContext.Current.Response.OutputStream.Write(resbyte, 0, resbyte.Length);
System.Web.HttpContext.Current.Response.FlushAsync();
|
|