我正在ASP.NET Core中使用WEB API。我正在取得结果。但是突然我变得异常 “ System.AggregateException:'值'无效。ameters = [{{parameters}],CommandType ='{commandT)'”
SocketException:现有连接被远程主机强行关闭。 IOException:无法从传输连接中读取数据:现有连接被远程主机强行关闭。 HttpRequestException:将内容复制到流时出错。
这是我的代码
{
string responseXML = string.Empty;
try
{
System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient { Timeout = new TimeSpan(0, 0, 500) };
var eP = "EndpointBAseURL" + url;
httpClient.BaseAddress = new Uri(eP);
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
System.Net.Http.StringContent content = new System.Net.Http.StringContent(requestData, System.Text.Encoding.UTF8, "application/json");
//Exception Happens in the following Line
System.Net.Http.HttpResponseMessage response = httpClient.PostAsync(eP,content).Result;
if (response.IsSuccessStatusCode)
{
responseXML = response.Content.ReadAsStringAsync().Result;
}
}
catch (WebException webEx)
{
responseXML = null;
WebResponse response = webEx.Response;
Stream stream = response.GetResponseStream();
String responseMessage = new StreamReader(stream).ReadToEnd();
//return responseMessage;
}
return responseXML;
}