2016-07-10 2 views
0

Apache HttpClient를 사용하여 스칼라 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 
    } 

문제는 Sourceio.Source에 빨간색으로 표시되어 있다는 점이다. 그것은 Cannot resolve symbol source라고합니다. 또한 import java.io._은 사용하지 않는 것으로 표시됩니다. 이 문제를 해결하는 방법?

답변

2

을 수행해야합니다

  • 자바 IO 라이브러리에없는 Source.fromInputStream(...)
2

소스 클래스와 io.Source.fromInputStream(...) 교체 import scala.io.Source

  • import java.io._ 교체

    이 줄을 추가하고 작동합니다

    import scala.io.Source