MVC POST远程主机关闭连接



我试图追踪错误,看看为什么我得到它。该页面是一个表单,它正在对API执行POST操作。我看到的唯一错误是remote host closed the connection。从日志中,我看到表单正在击中控制器并发送,但之后什么也没有。是否有其他异常可以帮助我理解这个错误?

误差

System.Web.HttpException (0x80070057): The remote host closed the connection. The error code is 0x80070057.
at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
at System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async)
at System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
at Telerik.Sitefinity.Modules.Libraries.Web.LibraryHttpHandler.

代码
protected ResultStatus FormCreate(requestWeb model)
{
var url = string.Format("Permission/SavePermissionRequestForm");
var result = ApiHelpers.Post<ResultStatus>("POST", url, model);

return result;
}

public static T Post<T>(string httpMethod, string url, object model)
{
try
{
var fullUrl = cmsApiUrl + url;
var json = JsonConvert.SerializeObject(model);
Stream dataStream = null;
WebRequest Webrequest;
Webrequest = WebRequest.Create(fullUrl);

Webrequest.ContentType = "application/json";
Webrequest.Method = WebRequestMethods.Http.Post;
Webrequest.PreAuthenticate = true;
Webrequest.Headers.Add("Authorization", "Bearer " + cmsApiKey);
byte[] byteArray = Encoding.UTF8.GetBytes(json);
Webrequest.ContentLength = byteArray.Length;
dataStream = Webrequest.GetRequestStream();
using (dataStream = Webrequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
WebResponse response = Webrequest.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
StringBuilder output = new StringBuilder();
output.Append(reader.ReadToEnd());
response.Close();
T result = JsonConvert.DeserializeObject<T>(output.ToString());
return result;
}
catch (Exception e)
{
T result = JsonConvert.DeserializeObject<T>("");
Elmah.ErrorSignal.FromCurrentContext().Raise(e);
return result;
}
}
  1. 这可能是服务器端问题。如果您控制了服务器端,请确保处理您返回的Stream(源)。
  2. 也,如果你有远程服务器的控制权,尝试启用缓冲。
  3. 从第三方(Telerik.Sitefinity)抛出异常。所以,正如其他人建议的那样-尝试从Postman或类似的工具做同样的请求,以更好地了解问题来自哪里。

我认为异常发生在您尝试再次读取流响应时,当它已经被读取和消费之前。您能指定此异常发生在代码的哪一行吗?这可以帮助我们给你一个更准确的答案。由于

相关内容

  • 没有找到相关文章

最新更新