Scala Dispatch Simple Get Request

岁酱吖の 提交于 2019-12-11 09:03:02

问题


I am trying to execute a Simple GET request with Scala Dispatch, however I am erroring out with a 404 error. Unexpected response status: 404

Here is a example that works:

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

But am I amunsure of where my error is in my code

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) 
} 

Thanks!


回答1:


If you print the composed URL (using composeUri(List("tsla", "goog")).url, for example), you'll see that it's different from your working example—it doesn't include the www subdomain. Change the definition of google to use www.google.com and this'll work as expected.



来源:https://stackoverflow.com/questions/21103553/scala-dispatch-simple-get-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!