【问题标题】:Query Parameters in Express being extracted?Express中的查询参数被提取?
【发布时间】:2013-11-05 07:24:41
【问题描述】:

我正在用 Node.JS 为 AppleScript 应用程序编写 API。 AppleScript 应用程序以这种形式在 shell 脚本中运行 curl

do shell script ("cd " & quoted form of myDir & "
curl http://localhost:5000/server.properties?some-value=true&next-value=something%20else&[...] -O")

它打算将一个名为server.properties的文件下载到目录myDir,其内容基于指定的参数,但由于某种原因,当Express收到请求时,它在我运行console.log(res.originalUrl)时只显示这个:

/server.properties?some-value=true

并且它将请求视为没有指定任何其他参数。谁能告诉我我做错了什么,或者如何找出问题所在?

EDIT 原来是我运行 shell 脚本的方式。需要引用 URL,以便 & 不会在 shell 脚本中充当运算符。

【问题讨论】:

  • 您是否尝试过在 URL 周围输出引号? & 是大多数 shell 中的运算符,可能会分解命令。
  • 哦!可能是这样,让我检查一下。
  • 这似乎是问题所在。我在 AppleScript 中使用了关键字quoted form of,发送的所有内容都很棒!做出答案,我会把它添加为正确的。
  • 是的,我知道。我打错了我的原始代码。

标签: node.js curl express request applescript


【解决方案1】:

我的解决方案如下:

do shell script ("cd " & quoted form of myDir & "
curl " & quoted form of (myUrl & myQuery) & " -O")

其中myUrl 设置为"http://localhost:5000/server.properties"myQuery 设置为"?some-value=true&next-value=something%20else&[...]"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-20
    • 2020-11-22
    • 2021-01-15
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 2018-10-10
    • 2016-11-29
    相关资源
    最近更新 更多