0

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;
        

     
  • 1
    I suggest reading the documentation to the remote resource thoroughly, Contact the owners / authors, try getting it to work in postman, use fiddler to look at the raw request, ect ect ect – TheGeneral Mar 04 '21 at 08:13
  • I am working on my pc and I have tested on postman and it's working fine but while i am consuming this post method i got this four error. – Vishant Vaghani Mar 04 '21 at 08:42
  • what am I asking is that in my solution i have two project 1.which is of webapi and second is of client which is consuming the web api methods.. so when i requesting this post methd from my client project i am getting this four errors....hope you are getting what am i saying??? – Vishant Vaghani Mar 04 '21 at 08:46
  • We cant answer this.... We dont know what your api is and what it expects, and how you have set it up. What are you trying to send it ? a json payload ? are you using the Authorize attribute? what is the raw request that is working in fiddler, so we can at least see what works? I think you need to read [ask] and https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/ – TheGeneral Mar 04 '21 at 08:52

0 Answers0