【问题标题】:Getting a 302 http redirect location with Databinder-Dispatch使用 Databinder-Dispatch 获取 302 http 重定向位置
【发布时间】:2011-12-05 01:30:02
【问题描述】:

使用 databinder-dispatch 0.8.3 我试图从 302 http 响应中获取重定向 url,但出现以下异常:

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.

我错过了什么?一如既往,提前感谢。

【问题讨论】:

    标签: scala http-headers databinder scala-dispatch


    【解决方案1】:

    以下作品:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 2014-01-09
      • 2012-08-18
      • 1970-01-01
      相关资源
      最近更新 更多