0

I have been following this link to understand how to use HttpClient to call a Web API Method. https://www.tutorialsteacher.com/webapi/consuming-web-api-in-dotnet-using-httpclient

The code of interest in the article is below with ‘client’ being the HttpClient object:

client.BaseAddress = new Uri("http://localhost:60464/api/");  //HTTP GET 
var responseTask = client.GetAsync("student"); 
responseTask.Wait(); 
var result = responseTask.Result;

Error results as follows:

 System.AggregateException: 'One or more errors occurred. (Failed to connect to localhost/127.0.0.1:443)'

Please understand my background in networking, IIS and the like is very limited.Most of my time is spent in code and SQL Sprocs. This is a personal project so I have to get this setup myself

If I replace localhost with my machines IP I get the following error:

One or more errors occurred. (java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.)'

So two questions:

  1. How do I install this needed certificate or settings or otherwise (again no idea about this configuration network stuff) but I do have IIS up and running with the Web API hosted and working
  2. If using ‘localhost’ is not supposed to work, what might be the reason this article is using it?

This is only for a personal development machine, yes at some point I am going to want it to work in the real world but for now I just need to get some ‘hello world’ stuff going before the end of times.

Chetan Rawat
  • 578
  • 3
  • 17
seanw432
  • 17
  • 8
  • can you provide a link please? I only see one that comes up with that and the solution in that doesnt work either https://stackoverflow.com/questions/53741754/javax-net-ssl-sslhandshakeexception-java-security-cert-certpathvalidatorexcepti – seanw432 Mar 11 '20 at 22:37
  • for your other question, https://stackoverflow.com/questions/5528850/how-do-you-connect-localhost-in-the-android-emulator – Jason Mar 11 '20 at 22:56
  • To the cert question, I fear that many of the links assume I have a cert. I assume I do not, however I have no idea either way. Looks like I will have to read a book or two on all this just to get the connection linked. also, it seems like a mountain of code in some of those examples just to get connection. or maybe do clear text for now – seanw432 Mar 11 '20 at 23:03
  • it's could possibly be an issue with Android requiring SSL, although I would expect a different error. Search on "android cleartext" – Jason Mar 11 '20 at 23:09
  • do you know if a cert needs to be installed on the machine or iis? I did try to set IIS to 'accept' on cert but that didnt make a difference. I guess the first thing I need to learn is 'does it need a cert?' – seanw432 Mar 11 '20 at 23:14
  • if you're using SSL it does. Otherwise, no. But you might need to configure your app to allow non-https connections. Or you might have IIS misconfigured so that it thinks it has one. – Jason Mar 11 '20 at 23:17
  • that is what I am thinking. I am trying the clear text solution but I would rather do it with security but maybe I can find the security answer later. I do suspect my IIS is not set correctly or I need a cert. but no idea where,what, how – seanw432 Mar 11 '20 at 23:19
  • 1
    well I got it to work with cleartext. not sure I want to make that as my answer so I might delete the question later https://devblogs.microsoft.com/xamarin/cleartext-http-android-network-security/ – seanw432 Mar 11 '20 at 23:35
  • Please try to pass direct url instead of localhost – Chetan Rawat Mar 12 '20 at 04:14

0 Answers0