【问题标题】:How to read query parameters in spray?如何在喷雾中读取查询参数?
【发布时间】:2017-07-03 14:35:48
【问题描述】:

我想在spray中获取String和integer等参数,例如:

http://localhost:8080/nexus?taskId=1&operatorId=3&version=10&day=12&hour=7&minute=3

我使用代码:

path("nexus"){
              get {
                 parameters('taskId.as[Int], 'operatorId.as[Int],'version.as[Int],'day.as[Int],'hour.as[Int]    ,'minute.as[Int])
                  {  (taskId,operatorId,version,day,hour,minute) =>
                    complete{s"$taskId"}
                     }       
                 }

我用这段代码来测试:

curl http://localhost:8080/nexus?taskId=1&operatorId=3&version=10&day=12&hour=7&minute=3

但它导致了这个错误:

Request is missing required query parameter 'operatorId'

和operatorId真的存在!

我不知道怎么办!

【问题讨论】:

    标签: scala http get spray


    【解决方案1】:

    代码是正确的。只需用双引号将 URL 括起来:

    curl "http://localhost:8080/nexus?taskId=1&operatorId=3&version=10&day=12&hour=7&minute=3"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多