Http Client
用于执行 HTTP 和 WebSocket 请求的异步客户端。
这是进行网络通信的核心接口。它提供了 get、post 等便捷方法,以及一个 高度可定制的 request 方法来满足各种复杂请求的需求。所有网络操作都是 非阻塞的,并返回一个 Deferred 对象,代表未来的计算结果。
Author
M8Test, [email protected], https://m8test.com
Functions
Link copied to clipboard
abstract fun get(scope: CoroutineScope, urlString: String, queryParametersJson: Map<String, String>?, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpClientResponse>
异步发起一个 HTTP GET 请求。
Link copied to clipboard
获取脚本上下文对象 ScriptContext.
Link copied to clipboard
异步获取指定 URL 的 Cookie 存储。
Link copied to clipboard
abstract fun post(scope: CoroutineScope, url: String, urlencodedBodyJson: Map<String, String>?, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpClientResponse>
异步发起一个 HTTP POST 请求,发送 application/x-www-form-urlencoded 类型的数据。 这常用于提交网页表单。
Link copied to clipboard
abstract fun postJson(scope: CoroutineScope, url: String, json: String?, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpClientResponse>
异步发起一个 HTTP POST 请求,发送 JSON 格式的数据。 Content-Type 头将自动设置为 application/json。
Link copied to clipboard
abstract fun postMultipart(scope: CoroutineScope, url: String, multipartBuilder: HttpClientMultipart.() -> Unit, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpClientResponse>
异步发起一个 HTTP POST 请求,发送 multipart/form-data 类型的数据。 这通常用于文件上传或包含混合内容的表单。
Link copied to clipboard
abstract fun prepareGet(scope: CoroutineScope, urlString: String, queryParametersJson: Map<String, String>?, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpStatement>
准备一个 HTTP GET 请求以供后续执行,但不立即发送。
Link copied to clipboard
abstract fun preparePost(scope: CoroutineScope, url: String, urlencodedBodyJson: Map<String, String>?, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpStatement>
准备一个 application/x-www-form-urlencoded 类型的 HTTP POST 请求以供后续执行。
Link copied to clipboard
abstract fun preparePostJson(scope: CoroutineScope, url: String, json: String?, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpStatement>
准备一个发送 JSON 数据的 HTTP POST 请求以供后续执行。 Content-Type 头将自动设置为 application/json。
Link copied to clipboard
abstract fun preparePostMultipart(scope: CoroutineScope, url: String, multipartBuilder: HttpClientMultipart.() -> Unit, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpStatement>
准备一个 multipart/form-data 类型的 HTTP POST 请求以供后续执行。
Link copied to clipboard
abstract fun prepareRequest(scope: CoroutineScope, urlString: String, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpStatement>
准备一个高度可定制的 HTTP 请求以供后续执行。
Link copied to clipboard
abstract fun request(scope: CoroutineScope, urlString: String, requestBuilder: HttpClientRequest.() -> Unit?): Deferred<HttpClientResponse>
异步发起一个高度可定制的 HTTP 请求。
Link copied to clipboard
abstract fun webSocket(scope: CoroutineScope, url: String, request: HttpClientRequest.() -> Unit?, webSocketSessionBuilder: WebSocketSession.() -> Unit): Job
建立一个 WebSocket 连接。