【问题标题】:separate GET request path from query variables将 GET 请求路径与查询变量分开
【发布时间】:2022-06-22 21:11:20
【问题描述】:

我有网址:http://www.localhost:8080/api/numbers/prime?amount=13 通过 GET 请求

我想获得 api/numbers/prime 有没有办法在 node.js vanilla 中做到这一点?

【问题讨论】:

    标签: node.js url


    【解决方案1】:

    您可以对字符串使用 JavaScript 拆分和切片方法。

    let url = "http://www.localhost:8080/api/numbers/prime?amount=13";
    let urlWithoutQuery = url.split("?")[0];
    let path = urlWithoutQuery.slice(25); // To get the value after http://www.localhost:8080
    

    【讨论】:

      猜你喜欢
      • 2020-04-02
      • 2023-04-04
      • 2012-04-11
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多