val client = new HttpClient
println("cateBrandCode URL:"+url)
val method = new GetMethod(url)
client.executeMethod(method)
//服务器状态
println("http status:" + method.getStatusLine.getStatusCode) //200
println("http version:" + method.getStatusLine.getHttpVersion) // HTTP/1.1
if(method.getStatusLine.getStatusCode!=200){
println("http status is not 200, system exit")
sys.exit(1) //获取白名单错误,任务退出
}
//返回信息
val response = method.getResponseBodyAsString
//解析JSON
import java.util
val res: util.Map[_, _] = JacksonUtil.jsonToBean(response, classOf[util.Map[_, _]])
// println("get response :"+ res)
//释放连接
method.releaseConnection()
```
Scala解析http请求
于 2023-02-13 11:41:05 首次发布