• 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
    
    • 1
    • 2
    • 3
    • 4

    2. 修改windows有个优先解析列表:

      hosts 添加 上去后, ping localhost,地址还是 ::1,原因是windows有个优先解析列表,当ipv6的优先级高于ipv4时,地址就是::1

      a. 查看 Windows 优先级列表

    netsh interface ipv6 show prefixpolicies
    
    • 1

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    在这里插入图片描述

    在这里插入图片描述

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

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

    在这里插入图片描述

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

    在这里插入图片描述

  • 相关阅读:
    No146.精选前端面试题,享受每天的挑战和学习
    发现智能合约中的 bug 的 7 个方法
    【剑指offer】数据结构——数
    树莓派高级开发------总线地址、物理地址和虚拟地址的认识
    风力等级划分
    MySQL逻辑架构整理
    Arduino开发实例-多机CAN-Bus通信(基于MCP2515)
    聚丙烯微孔膜的等离子体改性及DNA|有机自由基改性DNA-阳离子脂质复合体的应用
    springboot + vue实战
    关于操作系统
  • 原文地址:https://blog.csdn.net/M1234uy/article/details/126830628