我正在使用
httpClient
lib 来使用 scala 进行一些 REST API
调用。我可以发布数据。
我正在使用以下代码来阅读内容。但是,当我在 Spark Databricks Cluster 上运行时,它给了我一个错误。
val entity = response.getEntity
var content = ""
if (entity != null) {
val inputStream = entity.getContent
content = io.Source.fromInputStream(inputStream).getLines.mkString
inputStream.close()
}
错误
error: object Source 不是 package io 的成员 内容 = io.Source.fromInputStream(inputStream).getLines.mkString
有什么方法可以修复这个错误,或者用不同的方法来读取 HTTP 响应内容。
请尝试
import scala.io.Source
或者像这样使用完整的包名称:
content = scala.io.Source.fromInputStream(inputStream).getLines.mkString