2
我使用DataBinder的調度以供製作工作得很好,只要Web服務器返回一個404DataBinder的調度:獲得403響應的壓縮內容
如果請求失敗,Web服務器返回一個HTTP請求403狀態碼,並在響應正文中提供詳細的錯誤消息,如XML。
如何讀取xml正文(不管403),例如我怎樣才能讓調度忽略所有的403錯誤?
我的代碼如下所示:
class HttpApiService(val apiAccount:ApiAccount) extends ApiService {
val http = new Http
override def baseUrl() = "http://ws.audioscrobbler.com/2.0"
def service(call:Call) : Response = {
val http = new Http
var req = url(baseUrl())
var params = call.getParameterMap(apiAccount)
var response: NodeSeq = Text("")
var request: Request = constructRequest(call, req, params)
// Here a StatusCode exception is thrown.
// Cannot use StatusCode case matching because of GZIP compression
http(request <> {response = _})
//returns the parsed xml response as NodeSeq
Response(response)
}
private def constructRequest(call: Call, req: Request, params: Map[String, String]): Request = {
val request: Request = call match {
case authCall: AuthenticatedCall =>
if (authCall.isWriteRequest) req <<< params else req <<? params
case _ => req <<? params
}
//Enable gzip compression
request.gzip
}
}
問題是內容是原始gzip內容。通常我會在所有可能的地方使用val。 – user3001
有沒有辦法將內容傳遞給我之前定義的gzip和xml處理程序?我想要的是將錯誤內容解壓縮並解析爲XML – user3001
在最新的分發版本(0.11.2)中找不到「StatusCode(代碼,內容)」,只存在「StatusCode(code)」 。 – null