2014-01-13 2 views
1

Scala Dispatch로 간단한 GET 요청을 실행하려고하는데 404 오류로 오류가 발생했습니다. 예기치 않은 응답 상태 : 여기에 404Scala Dispatch Simple Get 요청

가 작동하는 예입니다

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

을하지만 amunsure 내 오류 내 코드에

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

감사되는 위치이다!

답변

3

예를 들어 composeUri(List("tsla", "goog")).url을 사용하여 작성한 URL을 인쇄하면 작업 예제와 다른 것을 볼 수 있습니다. www 하위 도메인은 포함되지 않습니다. google의 정의를 www.google.com을 사용하도록 변경하면 예상대로 작동합니다.

+1

또한 완료시이 스크립트가 sbt에서 나오지 않는 이유는 무엇입니까? –