【问题标题】:Scala Dispatch Simple Get RequestScala Dispatch 简单获取请求
【发布时间】:2014-02-01 22:08:48
【问题描述】:

我正在尝试使用 Scala Dispatch 执行一个简单的 GET 请求,但是我遇到了 404 错误。意外响应状态:404

这是一个有效的例子:

https://www.google.com/finance/info?infotype=infoquoteall&q=tsla,goog

但是我是否知道我的错误在我的代码中的位置

import dispatch._ , Defaults._  
object Main extends App {
  //concats a the proper uri together to send to google finance   
  def composeUri ( l:List[String]) = {   
    def google = host("google.com").secure
    def googleFinance = google / "finance" / "info" 
    def googleFinanceGet = googleFinance.GET
    val csv = l mkString "," 
    googleFinanceGet <<? Map("infotype"-> "infoquoteall", "q"->csv)   
  }   

  def sendRequest (uri:Req) = { 
    val res:Future[Either[Throwable,String]] = Http(uri OK as.String).either    
    res 
  } 
  val future  = sendRequest(composeUri(List("tsla","goog")))
  for (f <- future.left) yield println("There was an error" + f.getMessage) 
} 

谢谢!

【问题讨论】:

    标签: scala scala-dispatch


    【解决方案1】:

    如果您打印组合的 URL(例如使用 composeUri(List("tsla", "goog")).url),您会发现它与您的工作示例不同 - 它不包括 www 子域。将google 的定义更改为使用www.google.com,这将按预期工作。

    【讨论】:

    • 另外,为什么这个脚本在完成后没有从 sbt 中退出?
    猜你喜欢
    • 2017-10-22
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多