scala获取接口中的数据

代码如下:

//需要传入的某个参数是个数组
val set = new mutable.HashSet[Long]()
set.add(40929354653L)
set.add(611771548884L)
val arr = set.toArray
//把参数转换成json格式
val jsonObj = new JSONObject
jsonObj.put("streamerId", 5) //参数1
jsonObj.put("payStart", 1605186600000L) //参数2
jsonObj.put("payEnd", 1605194760000L) //参数3
jsonObj.put("itemIds", arr) //参数4
try {
  val body = Http("https://接口地址")
    .postData(jsonObj.toJSONString)
    .header("Content-Type", "application/json")
    .header("Charset", "UTF-8")
    .options(HttpOptions.readTimeout(100000)).asString.body
  println(s"==========body: $body==========")
} catch {
  case e: Exception => {
    println(e)
  }
}
原文地址:https://www.cnblogs.com/atBruce/p/13964862.html