我在Scala中使用针对Http的Dispatch Databinder库。
我有这个方法。
def testCheckPage(url:String):String = {
try {
var http = new Http
var request = new Request(url)
val req_with_agent = request <:< Map("User-Agent" -> "Mozilla/4.0")
val responseBody = Http (req_with_agent as_str)
responseBody.length.toString
} catch {
case ex: Exception if ex.getMessage == null => "Message: " + ex.toString
case ex: Exception => "Message: " + ex.getMessage
}
}对于某些java.nio.BufferUnderflowException,比如http://bae.cf.huffingtonpost.com,我会得到一个urls。知道怎么回事吗?
发布于 2009-11-08 09:24:34
当编码不匹配时,可能会在其他库(例如Source.fromUrl)中发生这种情况。我不确定如何在该库中设置编码,但是您提供的URL的编码是ISO-8859-1,我相信这将默认为UTF-8,从而导致该问题。
https://stackoverflow.com/questions/1685525
复制相似问题