liugezhou
V2EX  ›  Node.js

服务器部署的 node 服务,为什么 postman 请求不了

  •  
  •   liugezhou · Aug 6, 2024 · 4128 views
    This topic created in 831 days ago, the information mentioned may be changed or developed.

    遇到一个非常诡异的问题,还请各位大佬指点

    在阿里云服务器上用 pm2 部署了一个 node 项目。 本地的一个 vue 代码直接去访问这个 api.xxx.xxxx 的接口可以正常访问通。

    但是用 postman 去访问这个接口的时候,访问不通,postman 页面:Could not get response

    这是什么原因,有遇到过相同问题的吗?

    23 replies  •  2024-08-08 16:05:18 +08:00
    FaustY
    FaustY
    Aug 6, 2024
    1
    条件太少了,可能代理问题、或者 postman 请求拼的不对吧
    FaustY
    FaustY
    Aug 6, 2024
    2
    可以用 postman 你有问题的请求,生成一个 fetch 的代码,去你 Vue 的页面下执行一下,看看是不是报错,报错了大概率 postman 请求拼的不对。
    Dolov
    Dolov
    Aug 6, 2024
    3
    有没有可能是 vue 项目,中配置的 proxy 把请求路径转化了
    liugezhou
    liugezhou
    OP
    Aug 6, 2024
    4
    @Dolov 还是很诡异,浏览器直接输入 api.xxxx 这个接口地址是有返回的,本地项目也可以直接访问,就是在 postman 中就没有响应,我的 ngxin 配置和 ssl 配置都是新的,难道是因为 ssl 原因吗
    liugezhou
    liugezhou
    OP
    Aug 6, 2024
    5
    @FaustY 请求都对,就是没有反应,还没找到是什么原因。。
    liugezhou
    liugezhou
    OP
    Aug 6, 2024
    6
    我用 apifox 去访问这个接口也是可以通的,就 postman 不可以。。。
    catinsides
    catinsides
    Aug 6, 2024
    7
    都转成 curl 命令对比一下
    airycanon
    airycanon
    Aug 6, 2024
    8
    Postman 有没有关闭 SSL certificate verification ?
    liugezhou
    liugezhou
    OP
    Aug 6, 2024
    9
    @airycanon 关闭了的
    liugezhou
    liugezhou
    OP
    Aug 6, 2024
    10
    @catinsides 用 curl 在服务器上执行返回是正确的,本地命令后执行,
    curl -v POST https://api.xxx/login \
    -H "Content-Type: application/json" \
    -d '{"username":"test", "password":"test"}'

    直接返回了这个错误
    * Could not resolve host: POST
    * Closing connection
    curl: (6) Could not resolve host: POST
    * Host api.yxdjjz.cn:443 was resolved.
    * IPv6: (none)
    * IPv4: 47.95.68.15
    * Trying 47.95.68.15:443...
    * Connected to api.yxdjjz.cn (47.95.68.15) port 443
    * ALPN: curl offers h2,http/1.1
    * (304) (OUT), TLS handshake, Client hello (1):
    * CAfile: /etc/ssl/cert.pem
    * CApath: none
    * Recv failure: Connection reset by peer
    * LibreSSL/3.3.6: error:02FFF036:system library:func(4095):Connection reset by peer
    * Closing connection
    curl: (35) Recv failure: Connection reset by peer
    liugezhou
    liugezhou
    OP
    Aug 6, 2024
    11
    @catinsides 本地浏览器和本地项目都是可行的,curl 本地命令后就出现这个问题了
    liugezhou
    liugezhou
    OP
    Aug 6, 2024
    12
    突然想到,ssl 证书是申请的个人免费版本,难道跟这个有关系?
    siweipancc
    siweipancc
    Aug 6, 2024 via iPhone
    13
    更新下客户端证书
    liugezhou
    liugezhou
    OP
    Aug 6, 2024
    14
    @siweipancc postman 里面添加个人证书吗?直接是关闭证书校验了,我觉得是我配置的有问题,但是又能访问,,,
    ik
    ik
    Aug 6, 2024 via iPhone
    15
    @liugezhou #10
    curl -v -x POST ....
    ik
    ik
    Aug 6, 2024 via iPhone
    16
    POST 这个参数删掉应该也成
    amlee
    amlee
    Aug 6, 2024
    17
    curl -v -k -X POST https://api.xxx/login \
    -H "Content-Type: application/json" \
    -d '{"username":"test", "password":"test"}'
    siweipancc
    siweipancc
    Aug 6, 2024
    18
    你用北京阿里云没做备案? powershell7 执行下代码可以更直观看到原因
    `Invoke-WebRequest -Method GET -Uri http://api.yxdjjz.cn/login -SkipHttpErrorCheck -OutFile res.html && Invoke-Item res.html`
    liugezhou
    liugezhou
    OP
    Aug 7, 2024
    19
    @siweipancc 好像就是因为域名没备案的原因 感谢感谢🙏
    githmb
    githmb
    Aug 7, 2024
    20
    以为是 Bug ,结果是天朝的 Feature (
    liugezhou
    liugezhou
    OP
    Aug 7, 2024 via iPhone
    21
    @githmb 比较诡异的是 因为浏览器请求可以正常访问 😄
    就没有往备案这方面去想
    julyclyde
    julyclyde
    Aug 8, 2024
    22
    @liugezhou 既然没备案,那浏览器凭啥是成功的呢??
    liugezhou
    liugezhou
    OP
    Aug 8, 2024 via iPhone
    23
    @julyclyde 是啊 凭啥,客服说是因为不稳定什么因素
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1117 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 17:34 · PVG 01:34 · LAX 09:34 · JFK 12:34
    ♥ Do have faith in what you're doing.