我可以使用以下代码来获取查询字符串。
var query_string = request.query;
我需要的是原始未解析的查询字符串。我该如何获取? 对于以下的URL,查询字符串是{ tt: 'gg' }
,我需要tt=gg&hh=jj
等等...
http://127.0.0.1:8065?tt=gg
Server running at http://127.0.0.1:8065
{ tt: 'gg' }
query
不是request.query
。后者是由 express 添加的成员。 - Pero P.parse
方法。请改用new URL(req.url).search
,或者如果你不确定req.url
是绝对路径还是相对路径,请使用new URL(req.url, 'https://yourbasehere.com/').search
。详情请参见: https://nodejs.org/dist/latest-v14.x/docs/api/url.html#url_url_search - Chris Bartleyrequire('url').parse(request.url, true).query
- Athachai