使用IIS发布网站,使用localhost不能访问,但使用127.0.0.1可以访问“Post、Put、Delete 接口”
使用http://localhost:6008/swagger/index.html,操作 “Post、Put、Delete 接口”,报错:“400 Error: Bad Request”。
刚开始以为是配置问题,但是发现使用 http://127.0.0.1:6008/swagger/index.html ,接口可以调用成功,则排除接口及配置问题。
1. 先 ping localhost 检查地址是不是“127.0.0.1”
ping localhost,发现地址不是“127.0.0.1”,而是“ ::1”,使用的是ipv6的
2. ping 127.0.0.1 检查 地址
ping 127.0.0.1 地址正常
1. 在 C:\Windows\System32\drivers\etc.hosts 配置中检查是否有以下代码,没有则添上
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
::1 localhost
2. 修改windows有个优先解析列表:
hosts 添加 上去后, ping localhost,地址还是 ::1,原因是windows有个优先解析列表,当ipv6的优先级高于ipv4时,地址就是::1。
a. 查看 Windows 优先级列表
netsh interface ipv6 show prefixpolicies
b. 修改Windows优先级列表
netsh int ipv6 set prefix ::/96 50 0
netsh int ipv6 set prefix ::ffff:0:0/96 40 1
netsh int ipv6 set prefix 2002::/16 35 2
netsh int ipv6 set prefix 2001::/32 30 3
netsh int ipv6 set prefix ::1/128 5 4
netsh int ipv6 set prefix ::/0 3 5
netsh int ipv6 set prefix fc00::/7 1 11
netsh int ipv6 set prefix fec0::/10 1 12
netsh int ipv6 set prefix 3ffe::/16 1 13
在 启用或关闭Windows功能中 启用FTP服务器:
浏览器输入localhost,出现以下页面: