问题描述
在我的 PC 本地主机(Win10)中。我在 Kestrel 中启动了 asp.net core web app,端口是 8081。
我想在 wsl2 中使用 curl 命令来测试 Web 应用程序,我发现了问题。
在我的电脑中找到以下网址。
curl http://localhost:8081/hello (working)
curl http://127.0.0.1:8081/hello (working)
curl http://192.168.43.216:8081/hello (working)
curl http://172.25.208.1:8081/hello (working)
在 wsl2 中,我使用 curl 命令但效果不佳。
curl http://192.168.43.216:8081/hello (not working)
curl http://172.25.208.1:8081/hello (not working)
我的电脑本地主机网卡
Wifi
IPv4: 192.168.43.216
submask: 255.255.255.0
gatway: 192.168.43.1
vEthernet (WSL)
IPv4: 172.25.208.1
submask: 255.255.240.0
gatway:
这是我的 asp.net core web api 设置。
launchSettings.json
"PrometheusCoreTest": {
"commandName": "Project","launchBrowser": true,"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},"applicationUrl": "http://0.0.0.0:8081"
}
Web API 控制器
[ApiController]
public class TestController
{
[HttpGet("/hello")]
public string Hello()
{
return "hello,world";
}
}
我使用 netstat 查找 8081 端口并将防火墙设置为允许 8081 端口。
C:\WINDOWS\system32>netstat -ano | find "8081"
TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING 22092
TCP [::1]:2184 [::1]:8081 SYN_SENT 22972
但是 wsl2 中的结果 curl http://192.168.43.216:8081/hello
仍然不起作用。
如何通过 wsl2 访问 localhost Web 应用程序?我是否缺少某些设置?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)