1

我正在尝试使用 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) 
} 

谢谢!

4

1 回答 1

3

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

于 2014-01-14T00:17:19.427 回答