我正在尝试使用 HttpGet 调用 REST 终结点并传递用户凭据。
var content = ""
val httpClient : CloseableHttpClient = HttpClients.createDefault();
val httpResponse = new HttpGet(url)
httpResponse.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(“uname”,”pwd”),”UTF-8", false))
val response = httpClient.execute(httpResponse)
val entity = httpResponse.getEntity()
val inputStream = entity.getContent()
content = fromInputStream(inputStream).getLines.mkString
inputStream.close
httpClient.getConnectionManager().shutdown()
return content
看起来BasicScheme在“org.apache.http.impl.auth”中被弃用。关于如何前进的任何指示...提前致谢。
MYYA
相关分类