【问题标题】:send multiple request parmeter in get request in curl, only single parameter is going在curl的get请求中发送多个请求参数,只有一个参数会
【发布时间】:2017-04-12 18:19:57
【问题描述】:

我正在尝试通过命令行向我的 api 发出 curl 获取请求。

curl http://localhost:8080/getList?id=100&mrp=50&discount=0

但是当我在我的 api 中记录请求时,我得到:

&{GET /getList?id=100 HTTP/1.1 1 1  which means that only id is being sent through the request. I don't understand why it is happening.

【问题讨论】:

    标签: unix curl get


    【解决方案1】:

    当您使用多个由& 分隔的请求参数运行curl 命令时,unix 将& 视为符号以在后台执行上一个命令。它后面的所有其他内容都被视为单独的命令。

    在发送请求时将 url 用引号括起来

    curl "http://localhost:8080/getList?id=100&mrp=50&discount=0"
    

    【讨论】:

    • 复制/粘贴网址时没有看鼠标下方,愚蠢的错误。
    【解决方案2】:

    以下是Curl Get请求中只有id通过的原因:

    1. 如果您看到 CURL 命令,您会注意到您在此 GET 调用/请求中使用 & 将多个值传递给您的请求参数。

    curl http://localhost:8080/getList?id=100&mrp=50&discount=0

    1. 在 Linux/Unix 环境中,& 具有预定义的解释。它用于在后台运行任何命令。因此,如果& 出现在任何文本之后,则该文本被解释为命令,& 表示在后台运行此命令。

    2. & 之后的任何文本都被视为新命令。因此,Linux 将您的上述 Curl 获取请求解释为 3 个不同的命令:
      一世。 curl http://localhost:8080/getList?id=100&
      ii. mrp=50&
      iii. discount=0

    解决方案:避免 Unix/Linux 这种解释的解决方案是用双引号将您的 url 括起来 "

    curl "http://localhost:8080/getList?id=100&mrp=50&discount=0"

    这将帮助您将所有三个参数值传递给您的 curl 获取请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      • 2017-06-23
      • 1970-01-01
      • 2017-11-23
      • 2018-06-29
      相关资源
      最近更新 更多