IIS发布网站,使用localhost无法调用Post、Put、Delete接口

一、项目情景

  使用IIS发布网站,使用localhost不能访问,但使用127.0.0.1可以访问“PostPutDelete 接口”

二、问题描述

  使用http://localhost:6008/swagger/index.html,操作 “PostPutDelete 接口”,报错:“400 Error: Bad Request”。

调用API报错


  刚开始以为是配置问题,但是发现使用 http://127.0.0.1:6008/swagger/index.html ,接口可以调用成功,则排除接口及配置问题。

三、原因分析:

1. 先 ping localhost 检查地址是不是“127.0.0.1”
   ping localhost,发现地址不是“127.0.0.1”,而是“ ::1”,使用的是ipv6的
ping localhost

2. ping 127.0.0.1 检查 地址
   ping 127.0.0.1 地址正常

ping 127.0.0.1


四、解决方案

4-1 ping localhost 地址为 ::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

Windows优先级

  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

在这里插入图片描述

在这里插入图片描述

4-2 检查功能是否开启FTP

  在 启用或关闭Windows功能中 启用FTP服务器

在这里插入图片描述

  浏览器输入localhost,出现以下页面:

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值