l did some research and l was told l had to edit the applicationhost.config file and bind the local ip of my computer. after running ipconfig to get the ip of
my local computer(192.168.56.1) l edited the applicationhost.config file as below
<site name="FINALKAHPROJECT" id="2"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="C:\Users\SBSC QA TEAM\source\repos\FINALKAHPROJECT\FINALKAHPROJECT\FINALKAHPROJECT" /> </application> <bindings> <binding protocol="http" bindingInformation="*:56745:localhost" /> <binding protocol="http" bindingInformation="*:8080:192.168.56.1" /> </bindings> </site>
and below is the code in xamarin.forms for consuming the api
public async void Comic() { using(var httpClient = new HttpClient()){ var response = await httpClient.GetStringAsync("http://192.168.56.1:80/api/comic"); var comic = JsonConvert.DeserializeObject<List<Comic>>(response); comicList.ItemsSource = comic; } }
l get the error System.Net.WebException: 'Failed to connect to /192.168.56.1:80' after setting the solution to start multiple projects and running the webapp and mobile app as the same time.Help Please
Answers
can be this? https://www.davidbritch.com/2019/10/xamarin-connecting-to-localhost-over.html
@AlessandroCaliaro No. l dont have https issue. l just get an error will trying to consume my api in the mobile. The api works well on the web
The address
http://10.0.2.2:port
that points to127.0.0.1:port
on your host machine. See the link. It points to an IP, not the localhost. Try to change bindingInformation from 'localhost' to '127.0.0.1' in applicationhost.config.Refer to: https://stackoverflow.com/a/49352345/11083277