简体   繁体   English

Scala Dispatch Databinder库抛出java.nio.BufferUnderflowException

[英]Scala Dispatch Databinder library throws java.nio.BufferUnderflowException

I am using the Dispatch Databinder library for Http in Scala. 我正在Scala中将Dispatch Databinder库用于Http。

I have this method. 我有这种方法。

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 
  }
}

With certain urls, such as http://bae.cf.huffingtonpost.com , I am getting a java.nio.BufferUnderflowException . 使用某些网址,例如http://bae.cf.huffingtonpost.com ,我得到了java.nio.BufferUnderflowException Any idea whay? 有什么想法吗?

This can occur in other libraries (eg Source.fromUrl) when the encoding is mismatched. 当编码不匹配时,这可能会在其他库(例如Source.fromUrl)中发生。 I'm not sure how to set the encoding in that library, but the encoding for the URL you provided is ISO-8859-1 and I believe this would default to UTF-8, causing that problem. 我不确定如何在该库中设置编码,但是您提供的URL的编码为ISO-8859-1,我相信这将默认为UTF-8,从而导致该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM