【发布时间】:2013-02-18 17:00:57
【问题描述】:
当我在 Dispatch 中提出请求时,我会应用 Promise 并得到:
Left(dispatch.StatusCode: Unexpected response status: 400)
如何获取响应的实际文本?我正在使用 Solr,它仍然返回有价值的 JSON 以及失败的 HTTP 请求。
【问题讨论】:
标签: scala scala-dispatch
当我在 Dispatch 中提出请求时,我会应用 Promise 并得到:
Left(dispatch.StatusCode: Unexpected response status: 400)
如何获取响应的实际文本?我正在使用 Solr,它仍然返回有价值的 JSON 以及失败的 HTTP 请求。
【问题讨论】:
标签: scala scala-dispatch
看起来你写了如下内容:
Http(url OK as.String)
OK 提供了您在此处看到的简单错误处理。您可以使用> 更直接地获取结果。例如,如果你这样写:
Http(url("http://google.com/") OK as.String).either()
您将获得以下信息(至少目前):
Left(dispatch.StatusCode: Unexpected response status: 301)
但如果你做以下小改动:
Http(url("http://google.com/") > as.String).either()
您将获得重定向页面的完整正文:
res1: Either[Throwable,String] =
Right(<HTML><HEAD><meta http-equiv="content-type" ...
如果您想对响应做一些更有趣的事情,您可以编写自己的 asWhatever 处理程序 - 例如,请参阅我的回答 here 以演示如何以映射的形式访问标题。
【讨论】: