0
我正在使用Apache HttpClient創建一個Scala REST客戶端。 這是我的代碼。Scala中的REST客戶端問題
import java.io._
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.DefaultHttpClient
val output = getRestContent(myURL)
/**
* Returns the text content from a REST URL. Returns a blank String if there
* is a problem.
*/
def getRestContent(url:String): String = {
val httpClient = new DefaultHttpClient()
val httpResponse = httpClient.execute(new HttpGet(url))
val entity = httpResponse.getEntity()
var content = ""
if (entity != null) {
val inputStream = entity.getContent()
content = io.Source.fromInputStream(inputStream).getLines.mkString
inputStream.close
}
httpClient.getConnectionManager().shutdown()
return content
}
的問題是,Source
標記爲紅色的io.Source
。它說Cannot resolve symbol source
。此外import java.io._
被標記爲未使用。如何解決這個問題?