scala 回调函数
写法一:根据自己的scala版本号 导入依赖
<dependency>
<groupId>org.scalaj</groupId>
<artifactId>scalaj-http_2.12</artifactId>
<version>2.4.1</version>
</dependency>
然后执行http请求即可,简单soeasy
Http("https://"+callbakURL+":30140"+callBackPath).postData(json.toString)
.header("Content-Type", "application/json")
.header("Charset", "UTF-8")
.option(HttpOptions.readTimeout(10000)).asString
写法二:
第二种写法显然是有点啰嗦了,但是复杂业务需要自己封装的修改的地方的话,可以参考一下
object HttpUtil {
//get请求
def getResponse(url: String, header: String = null): String = {
val httpClient = HttpClients.createDefault() // 创建 client 实例
val get = new HttpGet(url) // 创建 get 实例
if (header != null) { // 设置 header
val json = JSON.parseObject(header)
json.keySet().toArray.map(_.toString).foreach(key =&g