3

I have created an Function App using Visual Studio 2017 and I created some APIs. That API was worked on my system very fine. But from another system its gets the "bad request / site can't be reached".

enter image description here

My question is, how can I call my API from the another system? Anyone please give me solution.

evilSnobu
  • 24,582
  • 8
  • 41
  • 71
Ismayil S
  • 223
  • 3
  • 20
  • `192.168.1.17` is your PC's IP address (local)? And you are running it locally? – juunas Jul 25 '18 at 06:24
  • Yes, it's my system IP but, it is also not working in my system . I'm using "localhost" instead on IP address. That's my problem I can't access my API with IP. – Ismayil S Jul 25 '18 at 06:39
  • See this - https://stackoverflow.com/a/49541736/4148708. `func host` isn't really meant to be used _as-is_ in production, should be wrapped by a heavy-duty reverse proxy like nginx. – evilSnobu Jul 25 '18 at 07:41
  • _What's wrong with Kestrel that it needs nginx on top?_ you may ask. Fair question. Probably nothing wrong with naked Kestrel, i opened an issue to get an answer from the folks that build the runtime - https://github.com/Azure/azure-functions-host/issues/3184 – evilSnobu Jul 25 '18 at 08:22
  • Have you bind 127.0.0.1 ip in your service so that your azure function can't be accessed by other ip except localhost. – Jay Gong Jul 25 '18 at 08:53

2 Answers2

3

If you created a v2 function, please check your function CLI output when debugging locally. At the third line, there should be Now listening on: http://0.0.0.0:7071

If you see Now listening on: http://localhost:7071, it means your function CLI is old so that it still binds to localhost, which stop you accessing function with your local IP.

Apparently solution is to use the latest CLI. On VS menus, Tools->Extensions and Updates, find Azure Functions and Web Jobs Tools, update it to latest version(15.0.40617.0). Then things should work with new CLI.

Note that local functions can only be visited by systems in the same LAN, otherwise you should make the function available in public, have a look at ngrok. And if you use v1 function, its latest CLI still binds to localhost, have to resort to tools like ngrok if needed.

Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
2

At VS debugging site, IIS Express and localhost + port are used by default.

In order to use IP address and multi domain debugging, we can find applicationhost.config under C:\Users\...\Documents\IISExpress\config\applicationhost.config and find the following code:

enter image description here

Add a similar line in the <bindings> tag:

 <binding protocol="http" bindingInformation="*:7071:192.168.1.17" />

Then open the CMD command window as an administrator:

netsh http add urlacl url=http://192.168.1.17:7071/ user=everyone

Finally, you can access this site with IP address

More information for your reference: IIS Express enable external request

Lee Liu
  • 1,981
  • 1
  • 12
  • 13