Xamarin VS2015 ios app connect to web app api - ios

I have a iOS app that I am building in Visual Studio 2015 with Xamarin. I also have a Web Application with an Api, no authorisation. But when I try to connect to the api I get an error saying "Connection Refused".
I call the api through the following code:
var client = new HttpClient();
var data = await client.GetAsync("http://localhost:7074/api/values/get");

Config your Web API with an IP Address, say local 192.168.x.x
And replace localhost by that IP
var data = await client.GetAsync("http://191.268.x.x:7074/api/values/get");

localhost will point to your iOS device/emulator, not the server. You need to specify the IP or FQDN in the url. Also be be sure the firewall is open and that IIS is setup to accept remote connections.

localhost is your iPhone / iPad or simulator (the device where you run your app). You have to change it to the IP/Domain of your server.
If the server is your dev machine, ensure, that your phone is connected to the same network (e.g. via WiFi), else you might have the same problem, because your dev machine might not be reachable.
You can find the IP of your dev machine by typing ipconfig | find "IPv4" into the console (on Windows).

Related

Is there a workaround to configure host to address mapping on hosts file on iPad?

I need to connect to a work remote server via work VPN (the server is web GUI so connection is via https) which requires hosts resolution, meaning I have to configure the host name and map to the IP address in the hosts file. This is how I connect to the remote server on my Mac.
I just got a new iPad 2020 and I will like to connect to the server on my iPad.
For me to access the hosts file on iPad, I will have to jailbreak of which I don’t wanna do that. I’ve read counts of articles online on how to go about using some other apps, but it only works for if your server and your device are both on thesame network and VPN is not used.
Appreciate if there is a workaround for me to do this:
I need to connect via work VPN;
Access the server using the host name on safari etc.
Thanks.

How to connect to localhost on a real device in react native on iOS?

I have a server running on localhost:5000 on my desktop, and when I make http requests through my react-native app when running on the iOS simulation to it, it works. However, when I connect to a real device, the http requests don't work. What am I doing wrong? Is there something I have to configure?
localhost in your desktop is not the same ip of the localhost of your device.
Get the ip of your computer by typing ifconfig in a terminal, then replace localhost by this ip, you should type something like that in your device browser:
192.168.0.23:5000
Maybe my answer is too late but I ran into a similar situation today and I got it to work by running my node server using the IPv4 of my desktop and then making the request to that IP.
For example, I am running my nodejs development server at http://192.168.0.135:3000(local IP of my desktop) instead of localhost and then I make the fetch API request from my react-native app to http://192.168.0.135:3000/.
Just make sure your nodejs server and your app are on the same local network. My react-native server (metro bundler) is running on a separate PC also in the same wifi network.
If your are on macOS go to settings -> Wifi / and show more,
on bottom you see "IP address", it's your correct localhost for ios physical device !

How can I access my localhost on my computer from my Android device?

I have a web application written in ASP.NET MVC 5. I simply can open it from the browser with this localhost:14920 in my computer, but I want to access the same application from my Android device's browser while my laptop and Android device are in the same network. I don't know how to access it from Android.
Note: when I type 127.0.0.1 in the Android browser I can access the IIS server, but when I type 127.0.0.1:14920 it prints Bad Request - Invalid Hostname. How can I fix this issue?
You can configure IISExpress for remote access
http://www.ryadel.com/en/iis-express-allow-external-requests-remote-clients-devices/
or just change the hosting to IIS as the earlier commenter mentioned.
Try with replacing 127.0.0.1 with your IPv4 address.
I have used ngrok in the past, when needing to hit my development machine, or have someone else hit it. It is a very useful tool and very simple to install.
Once you download it, it's just a simple command line:
https://ngrok.com/docs#expose
ngrok http 80
(That is for traffic on port 80) Since your port above looks different it would be:
ngrok http 14920
That will give a URL that you can hit or any machine or device.

Test Website on Local Network

I'm a web developer that's not very savvy when it comes to networking. I have a web site that is on my local machine. I've setup the website so that it is currently running on my local IIS. I can access the website while doing development by putting http://localhost:11000/ into the address bar of my browser. Now, I want to test my website on a tablet.
My tablet and my local development machine are on the same network. I confirmed they are hitting the same router. When I ask Google what my IP address is, it returns the same address for both my development machine and on my tablet. When I enter [ipAddress]:11000 into the browser on my tablet, it works for a while and then returns nothing. The browser just says:
"Safari could not open the page because the server stopped responding."
My question is, how do I test a website from my local development machine on my tablet? Are there IIS settings I need to change? If so, what settings?
Thank you!
iis ipad
I would use the command window and enter ipconfig to discover the ip address of your dev machine. Then use that IP address on your remote machine (ipad). The IP address you are getting that is the same between your workstation and your ipad is likely your router's address. but each of your devices has an address of its own; you need the workstation's IP address to connect to its IIS instance.
A similar question was answered previously at:
How to access your website through LAN in ASP.NET

Connect to local web service (running under MAMP) from iPhone via WIFI.

I have setup a local REST webservice with MAMP.
I have setup a virtual host with the url "http://aem.davidcasillas" pointing to my public folder.
MAMP is listening on port 80.
If I access via Safari to "http://aem.davidcasillas/webservice/rest/getEventosToday" I get the correct json data.
Now I'm trying to access this web service from my iPhone application. I run it from XCode into the device.
The device is connected to my local network via WIFI, and the connection is working (I can load webpages in safari)
I'm using RestKit to download the data and I'm trying to reach it with the same url I use in my Mac: "http://aem.davidcasillas.es/webservice/rest/getEventosToday".
In the device I get the error:
NSURLErrorDomain -1003 Found no server for the specified host name.
How should I write my url so I can reach the web service from the iPhone?
NOTE: I have read this post: test local websites with mamp on iphone? but none of this problems apply to my case. I have firewall disabled and my config.ini file shows the following listen line:
Listen 80
I have found a workaround.
I use the WIFI ip address in SystemPreferences->NetWork in my Mac and then the whole path to the resource, so instead of:
"http://aem.davidcasillas.es/webservice/rest/getEventosToday"
I am writing:
"http://192.168.1.6/aem.davidcasillas.es/public/webservice/rest/getEventosToday"
The 192.168.1.6part takes me to my local installation root folder /Applications/MAMP/htdocs/.
In the rest of the path I have to put the whole path to the resource. Notice that I have to include the public folder in the path. Hope I could use my virtual host setup, but have not found a way.
When I run hostname, it prints out
> hostname
ddopson.local
You can edit this in System Preferences ==> Sharing ==> Computer Name(text box at the top). Note that in the "computer name" textbox, I filled in "ddopson".
If you are on WiFi, you should be able to connect to that hostname (ddopson.local) from your iPhone. This works because both iOS and your Mac support Multicast DNS where a multi-cast UDP packet is emitted onto the L2 network to lookup local hostnames. When your Mac hears this multi-cast packet, it will reply to your iPhone with its ip-address and off you go.

Resources