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

    在这里插入图片描述

  • 相关阅读:
    mybatis中按照时间搜索功能
    vue3+vite搭建项目(七)
    Flask 表单以及表单验证
    【浅学Java】哈希桶的模拟实现以及HashMap原码分析
    CentOS 7.x 安装MongoDB
    电工三级证(高级)实战项目:信号交通灯的PLC控制
    Jmeter使用
    使用gitee go将spring boot项目部署到云主机上并运行
    Spring Cloud Loadbalancer
    【见刊通知】ISEEIE 2022 & COMSE 2022已见刊,请自行查看见刊链接 ~
  • 原文地址:https://blog.csdn.net/M1234uy/article/details/126830628