Sujeet Raman

Sujeet Raman

  • 857
  • 927
  • 357.4k

No connection could be made because the target machine actively refuse

Feb 8 2021 7:57 AM
I have two asp.net core 3.1 api solution . I am trying to call port number 2005 from port number 2001 using http client
 
public const string _callurl = "http://localhost:2005/api/Product/Productspecific";
 
.i am getting exception like No connection could be made because the target machine actively refuse what will be the issue?
  1. public async Task<Resultclass> ResultcallHttpclient(Input input)  
  2. {  
  3. var requestUri = string.Format(UrlPatterns._callurl, _Uri);  
  4. StringContent content = new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json");  
  5. var httpResponse = await _singleton.Client.PostAsync(requestUri,content);  
  6. switch (httpResponse.StatusCode)  
  7. {  
  8. case HttpStatusCode.OK:  
  9. var jsonResponse = await httpResponse.Content.ReadAsStringAsync();  
  10. return JsonConvert.DeserializeObject<Resultclass>(jsonResponse);  
  11. case HttpStatusCode.NotFound:  
  12. return QualityCheckResults.CreateAsNotFound();  
  13. default:  
  14. }  
  15. }  

Answers (19)