• 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,出现以下页面:

    在这里插入图片描述

  • 相关阅读:
    追寻上古文明毕业季研学营
    机器学习 之 python实现正规方程
    洛谷P8395 Good Fours and Good Fives
    书生·浦语大模型开源体系(四)作业
    肝内胆管结石有哪些严重危害?
    数组专题总结
    Redux(mvc、flux、react-redux)
    快排,代码思路详解
    Mybatis-plus学习笔记
    辽宁CA与契约锁达成合作,携手推动辽宁省电子劳动合同订立及备案
  • 原文地址:https://blog.csdn.net/M1234uy/article/details/126830628