使用Databinder-Dispatch获取302 http重定向位置

时间:2011-10-11 06:56:08

标签: scala http-headers databinder scala-dispatch

使用databinder-dispatch 0.8.3我试图从302 http响应中获取重定向网址,但是我得到以下异常:

Caused by: dispatch.StatusCode: Unexpected response code: 302

这是我尝试过的some help

import dispatch._
import org.apache.http.{HttpRequest,HttpResponse}
import org.apache.http.protocol.HttpContext
import org.apache.http.HttpStatus._

val http = new Http { 

  override def make_client = { 
    val client = new ConfiguredHttpClient(new Http.CurrentCredentials(None))

    client.setRedirectStrategy(new org.apache.http.impl.client.DefaultRedirectStrategy {      
        override def isRedirected(req: HttpRequest, res: HttpResponse, ctx: HttpContext) = false 
    })

    client 
  }
}

val req: Request = :/("graph.facebook.com") / "kmels" / "picture" 

val pictureURL: String = http(req.secure >:> { _("Location").head }) //error prone code, but we're just testing. This is the line where the exception is thrown.

我错过了什么?一如既往,先谢谢。

1 个答案:

答案 0 :(得分:1)

以下作品:

val pictureURL: String = http.x(req.secure >:> { _("Location").head })