【发布时间】:2022-06-22 21:11:20
【问题描述】:
我有网址:http://www.localhost:8080/api/numbers/prime?amount=13 通过 GET 请求
我想获得 api/numbers/prime 有没有办法在 node.js vanilla 中做到这一点?
【问题讨论】:
我有网址:http://www.localhost:8080/api/numbers/prime?amount=13 通过 GET 请求
我想获得 api/numbers/prime 有没有办法在 node.js vanilla 中做到这一点?
【问题讨论】:
您可以对字符串使用 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
【讨论】: