无法使用ip:port访问WEB API,但可以在VS调试模式下使用localhost:port [英] Can't access WEB API with ip:port but can with localhost:port during VS debug mode
问题描述
我正在尝试从.net编写一个WEB API,并尝试使用我的Android应用程序来查询sql server数据库中的一些数据。我的问题是我注意到该应用程序的URL是 localhost:port
它运行正常。
但是,当我尝试将其更改为 MYIP:port(例如http:192.168.X.1234)
或 MYHOSTNAME:port (例如win7home:1234)
这给我错误请求 - 无效的主机名
。
我知道我可以将它部署到IIS,我的IIS是设置,但我只是想知道它是如何在调试模式下不起作用?
有没有办法让我在调试模式下运行它,同时在我的Android上测试,而不是每次我想要更改?
安东和马修的答案都指向正确的方向
所以这样我做了
1)以管理员模式运行Visual Studios
2)绑定协议并允许建议的传入方向
http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer
- 之后,我有一个服务不可用(503)错误
3)所以我遵循:
IIS Express启用外部请求 - 503
只添加了端口协议和端口: ip协议,
< bindings>
< binding protocol =httpbindingInformation =:1904:/>
< binding protocol =httpbindingInformation =:1904:10.1.10.123/>
< / bindings>
比在我机器的浏览器和手机上都有效。
不太确定为什么需要第三步 - 假设是(VS需要localhost url指向,ip url用于从另一台机器访问)
I am trying to write an WEB API from .net and trying for my Android Application to query some data from the sql server database.
I have the web api written and it works well in debug mode.
My question is I notice the url of that application is localhost:port
and it runs fine.
However, when I try to change it to MYIP:port (eg. http:192.168.X.1234)
or MYHOSTNAME:port (eg win7home:1234)
this gives me Bad Request - Invalid Hostname
.
I know I can deploy this to IIS and my IIS is setup but I was just wondering how come it doesn't work in debug mode???
Is there a way for me to run it in debug mode and test in on my Android at the same time instead of having to deploy it every time I want to make a change?
Both Anton and Matthew's Answers pointed me to the right direction
So this what I did
1)Run Visual Studios in administrator mode
2)Changed the binding protocols and allow for incoming directions as suggested http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer
-But after that, I have a service unavailable (503) error
3)So I followed this : IIS Express Enable External Request - 503 Added just the port protocol and port:ip protocol,
<bindings>
<binding protocol="http" bindingInformation=":1904:" />
<binding protocol="http" bindingInformation=":1904:10.1.10.123" />
</bindings>
Than it works both on my machine's browser and on my phone.
Not too too sure why the 3rd step is needed -my hypothesis is (the localhost url is needed for VS to point to and the ip url is used for accessing from another machine)
这篇关于无法使用ip:port访问WEB API,但可以在VS调试模式下使用localhost:port的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!