This is the method where I am requesting post request but I am getting following error Basically I am consuming post method in the client side code **
error
 ** System.AggregateException
      HResult=0x80131500
      Message=One or more errors occurred.
      Source=mscorlib
      StackTrace:
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at System.Threading.Tasks.Task`1.get_Result()
       at Client.team.AddTeam() in K:\LiveScoreSystemWebApi\Client\team.aspx.cs:line 259
       at Client.team.GoBtn_Click(Object sender, EventArgs e) in K:\LiveScoreSystemWebApi\Client\team.aspx.cs:line 51
    
      This exception was originally thrown at this call stack:
        [External Code]
    
    Inner Exception 1:
    HttpRequestException: An error occurred while sending the request.
    
    Inner Exception 2:
    WebException: The underlying connection was closed: An unexpected error occurred on a receive.
    
    Inner Exception 3:
    IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
    
    Inner Exception 4:
    SocketException: An existing connection was forcibly closed by the remote host
**   
    
    ----------
Code
HttpClient client = new HttpClient();
     client.BaseAddress = new Uri("http://localhost:44382/api/Team");                
     MediaTypeFormatter[] formatter = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };
     HttpContent content = new ObjectContent<Team>(team1, formatter[0]);
     HttpResponseMessage response = client.PostAsync(client.BaseAddress +"/insertTeam",content).Result;
        
     
User contributions licensed under CC BY-SA 3.0