Scala and HttpClient: How do I resolve this error?

Posted by Benjamin Metz on Stack Overflow See other posts from Stack Overflow or by Benjamin Metz
Published on 2010-04-22T19:58:45Z Indexed on 2010/04/23 8:43 UTC
Read the original article Hit count: 287

Filed under:
|

I'm using scala with Apache HttpClient, and working through examples. I'm getting the following error:

/Users/benjaminmetz/IdeaProjects/JakartaCapOne/src/JakExamp.scala
   Error:Error:line (16)error: overloaded method value execute with alternatives 
(org.apache.http.HttpHost,org.apache.http.HttpRequest)org.apache.http.HttpResponse 
<and> 
(org.apache.http.client.methods.HttpUriRequest,org.apache.http.protocol.HttpContext)org.apache.http.HttpResponse
 cannot be applied to 
(org.apache.http.client.methods.HttpGet,org.apache.http.client.ResponseHandler[String])
val responseBody = httpclient.execute(httpget, responseHandler)

Here is the code with the error and line in question highlighted:

import org.apache.http.client.ResponseHandler
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.BasicResponseHandler
import org.apache.http.impl.client.DefaultHttpClient


object JakExamp {
 def main(args : Array[String]) : Unit = {
   val httpclient: HttpClient = new DefaultHttpClient
   val httpget: HttpGet = new HttpGet("www.google.com")

   println("executing request..." + httpget.getURI)
   val responseHandler: ResponseHandler[String] = new BasicResponseHandler
   val responseBody = httpclient.execute(httpget, responseHandler)
   // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   println(responseBody)

   client.getConnectionManager.shutdown

 }
}

I can successfully run the example in java...

© Stack Overflow or respective owner

Related posts about scala

Related posts about httpclient